If the user makes an incorrect product category selection, prompt the user to re-enter a valid product category.
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.");
}
}
}
}
Comments
Leave a comment