'How to print number 1 to 10(in that sequence only)using loops(java) if int i = 10

Output must be 1 2 3 4 5 6 7 8 9 10

I have tried While loop but it prints from 10 to 1



Solution 1:[1]

Assuming you must use i with an initial value of 10.

for(int i = 10; i > 0; i--) {
    System.out.println(11-i);
}

// or using a while loop
int i = 10;
while(i > 0) {
    System.out.println(11-i--);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1