Write a java program to print all natural numbers in reverse(from n to 1) - using while loop
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
     //Write a java program to print all natural numbers in //reverse(from n to 1) - using while loop
  Scanner cin=new Scanner(System.in);
  System.out.print("Please enter n:");
  int n=cin.nextInt();
    //reverse print use while loop
    while(n!=0)//until n no equal 0
      {
        System.out.print(n+"  ");//print to standart out
        n--;
      }
  }
}
Comments