Answer to Question #278353 in Java | JSP | JSF for Adeng

Question #278353

Using WHILE LOOP

Write a Program that will ask the user to accept an

integer input and outputs message below:

Choose what you want to print:

1. Print Hello Philippines

2. Print Numbers Ascending (from 1)

3. Print Numbers Descending (from 1000)


Enter the number that you want to print:

Number of iterations:



1
Expert's answer
2021-12-11T01:58:01-0500
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    
    System.out.printf("Enter the number that you want to print:");
    int number = scanner.nextInt();
    
    System.out.printf(" Hello Philippines\n");

    int i = 1;
    System.out.printf("Numbers Ascending (from 1): ");
    while (i <= number)
      System.out.printf("%d ", i++);
    System.out.printf("\n");

    int i = 1000;
    System.out.printf("Numbers Descending (from 1000): ");
    while (i >= number) 
      System.out.printf("%d", i--);
    System.out.printf("\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