Print 1 to 10 without using loop in java?
public class PrinWithoutLoop{
public static void print(int n){
if(n<=10){
System.out.println(n);
print(n+1);
}
}
public static void main(String [] args){
print(1);
}
}
Output:
1
2
3
4
5
6
7
8
9
10
Comments
Post a Comment