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:
output here:
import java.util.Scanner;
public class App {
/**
* The start point of the program
*
* @param args
*
*/
public static void main(String[] args) {
Scanner keyBoard = new Scanner(System.in);
System.out.println("1. Print Hello Philippines");
System.out.println("2. Print Numbers Ascending (from 1)");
System.out.println("3. Print Numbers Descending (from 1000)");
System.out.print("Choose what you want to print: ");
int ch = keyBoard.nextInt();
if (ch == 1) {
System.out.println("Hello Philippines");
} else if (ch == 2) {
System.out.print("Number of iterations: ");
int numberPrint = keyBoard.nextInt();
for (int i = 1; i <= numberPrint; i++) {
System.out.print(i + " ");
}
} else if (ch == 3) {
for (int i = 1000; i >= 0; i--) {
System.out.print(i + " ");
}
} else {
System.out.println("Wrong selection");
}
keyBoard.close();
}
}
Comments
Leave a comment