Java Topics

Display the numbers without using any loop conditions

public class WithoutLoop {

public static void main(String[] args) {

  loop(1);

   }

   public static void loop(int num) {

   if(num<=10) {

   System.out.println(num);

   loop(num+1);

   }

   }

}

Output:

1
2
3
4
5
6
7
8
9
10