Answer to Question #330189 in Java | JSP | JSF for Mark

Question #330189

Write a java program to print all natural numbers in reverse(from n to 1) - using while loop

1
Expert's answer
2022-04-20T03:44:58-0400



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--;
      }
  }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS