How to print 1 to 30 without loop in Java

1 Answer

0 votes
public class MyClass {
    public static void print1_to_30(int number) {
		if (number <= 30) {
			System.out.print(number + " "); 
			print1_to_30(number + 1);
		}	
	}
    public static void main(String args[]) {
        int number = 1;
		
		print1_to_30(number);	
    }
}





/*
run:
 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 
 
*/

 

 



answered Oct 8, 2021 by avibootz

Related questions

1 answer 148 views
1 answer 96 views
1 answer 187 views
1 answer 239 views
1 answer 116 views
116 views asked Oct 8, 2021 by avibootz
1 answer 120 views
120 views asked Oct 8, 2021 by avibootz
1 answer 181 views
...