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:
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");
}
}
Comments
Leave a comment