Answer to Question #278824 in Java | JSP | JSF for ack

Question #278824

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:



1
Expert's answer
2021-12-12T12:19:08-0500


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

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