Answer to Question #238184 in Java | JSP | JSF for Nemo

Question #238184

If the user makes an incorrect product category selection, prompt the user to re-enter a valid product category.


1
Expert's answer
2021-09-17T15:31:39-0400
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String category;
        while (true) {
            System.out.println("Chose the category:\nTV\nPhones\nGames");
            category = in.nextLine();
            switch (category) {
                case "TV":
                case "Phones":
                case "Games":
                    System.out.println("Category accepted.");
                    System.exit(0);
                default:
                    System.out.println("Invalid category. Try again.");
            }
        }
    }
}

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