Answer to Question #317312 in Java | JSP | JSF for Radbebop

Question #317312

Ask the user for an integer then ask the user if he/she wants to count up or down. Display a table of numbers where the first column contains the counter, the second column contains the counter plus 10, and the third column contains the counter plus 100. Make it so each number takes up 5 spaces total. If counting up, the first column should contain numbers 1 through the user input; If counting down, the first column should contain numbers -1 through the the negative of the user input; Do user input validation on the word "up" and "down". Allow for any case.


1
Expert's answer
2022-03-24T16:26:26-0400


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);
		String answer = "";


		while (answer.compareToIgnoreCase("up") != 0 && answer.compareToIgnoreCase("down") != 0) {
			System.out.print("Do you want to count 'up' or 'down'?: ");
			answer = keyBoard.nextLine();
		}
		if (answer.compareToIgnoreCase("up") == 0) {
			for (int i = 1; i <= 5; i++) {
				System.out.printf("%-5d%-5d%-5d\n", i, (i + 10), (i + 100));
			}
		} else {
			for (int i = -1; i >= -5; i--) {
				System.out.printf("%-5d%-5d%-5d\n", i, (i + 10), (i + 100));
			}
		}
		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