Skip to content

Commit 4df163d

Browse files
committed
feat: Print first N natural numbers in reverse order using for loop
🧠 Logic: - Program prompts the user to enter a number `n`. - A for-loop runs from `n` down to 1, printing each number. - Demonstrates basic input handling and reverse-order iteration. - Suitable for practicing loop constructs and Scanner usage. Signed-off-by: Somesh diwan <[email protected]>
1 parent fb7e4d6 commit 4df163d

File tree

1 file changed

+0
-5
lines changed

1 file changed

+0
-5
lines changed

Section9ArrayAB/Array IMP/ReverseNumberPrint.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ public class ReverseNumberPrint {
44
public static void main(String[] args) {
55
Scanner scanner = new Scanner(System.in);
66

7-
//Ask the user for the number of natural numbers to print
87
System.out.print("Enter the number, to print natural numbers in reverse order: ");
98
int n = scanner.nextInt();
109

@@ -20,9 +19,7 @@ public static void main(String[] args) {
2019
Do-While:
2120
2221
Initialize the loop variable
23-
2422
int i = n;
25-
2623
Use a do-while loop to print numbers in reverse order.
2724
2825
do {
@@ -34,9 +31,7 @@ public static void main(String[] args) {
3431
While:
3532
3633
Initialize the loop variable
37-
3834
int i = n;
39-
4035
Use a while loop to print numbers in reverse order
4136
4237
while (i >= 1) {

0 commit comments

Comments
 (0)