求助,如何结束SWITCH结构下的DO-WHILE循环
import java.util.Scanner;public class liling33{
public static void main (String[] args){
System.out.println("\t\t\t\t欢迎使用我行我素购物管理系统>真情回馈\n\n");
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println("\t\t\t\t\t1. 幸运大放送\n\n");
System.out.println("\t\t\t\t\t2. 幸运抽奖\n\n");
System.out.println("\t\t\t\t\t3. 生日问候\n\n");
System.out.println("请输入数字:\n\n");
System.out.println("请选择,输入数字或按0返回上一级菜单\n\n");
Scanner input =new Scanner (System.in);
int num=input.nextInt();
switch(num){
case 0:
System.out.println("执行返回上一级菜单\n\n");
System.out.println("程序结束");
case 1:
System.out.println("执行幸运大放送\n\n");
System.out.println("程序结束");
break;
case 2:
System.out.println("执行幸运抽奖\n\n");
System.out.println("请输入4位会员号:\n");
int custNo=input.nextInt();
int qianwei=custNo/1000;
int baiwei=custNo%1000/100;
int shiwei=custNo%100/10;
int gewei=custNo%10;
int total;
total=qianwei+baiwei+shiwei+gewei;
if (total<=20){
System.out.println(custNo+"\t\t谢谢您的支持\n\n");
}else {
System.out.println(custNo+"\t\t是幸运客户,获精美MP3一个。\n\n");
}
String answer ="y";
System.out.println("\n是否继续(y/n)");
answer =input.next();
do{
if (total<=20){
System.out.println(custNo+"\t\t谢谢您的支持\n\n");
}else {
System.out.println(custNo+"\t\t是幸运客户,获精美MP3一个。\n\n");
}
}while(answer.equals("y"));
System.out.println("程序结束");
break;
case 3:
System.out.println("执行生日问候\n\n");
System.out.println("程序结束");
break;
default:
System.out.println("输入错误。\n\n");
System.out.println("程序结束");
break;
}
}
}
各位大虾,我每次运行程序到:while(answer.equals("y"));按Y都会陷入死循环,请问:如何结束它并输入下一个?????(按N会循环一次)
谢谢!!