2. Write a Java program to print all natural numbers in reverse (from n to 1). - using while loop
Sol :-
Static
class loop2
{
public static void main(String args[])
{
int i,start=10;
for(i=start;i>=1;i--)
{
System.out.println(i);
}
}
}
Output :-
Dynamic
import java.util.*;
class loop2
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int i,start;
System.out.println("Enter the Number :-");
start = in.nextInt();
for(i=start;i>=1;i--)
{
System.out.println(i);
}
}
}
Output :-