-1
如果用戶輸入'N',我該如何讓程序退出?如果用戶輸入'N',我該如何讓程序退出?
Scanner scan = new Scanner(System.in);
System.out.println("Would you like to buy and dairy products? Y/N ");
String answer = scan.nextLine();
switch (answer)
{
case "Y":
case "y":
System.out.println("\nHere are our list of dairy products:-");
break;
case "N":
case "n"://exit from program;
System.out.println("You don't want any dairy items");
break;
default :
System.out.println("Invalid choice, please select Yes/No bu entering the characters 'Y'/'N'");
break;
}