Skip to content

Commit c6280f3

Browse files
committed
feat: Print first 10 natural numbers in reverse using while loop
🧠 Logic: - Initialize a counter `i` to 10. - Use a `while` loop to print numbers from 10 down to 1. - Decrement `i` after each iteration. - Demonstrates reverse iteration using a basic `while` loop structure. Signed-off-by: Somesh diwan <[email protected]>
1 parent 4df163d commit c6280f3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
Program to Print First 10 Natural Numbers in Reverse Order Using while Loop.
3+
*/
4+
5+
public class ReverseNaturalNumbers {
6+
public static void main(String[] args) {
7+
int i = 10; // Initialize the counter to 10
8+
while (i >= 1) {
9+
System.out.println(i); // Print the number
10+
i--; // Decrement the counter
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)