Eclipse 我的循环不断循环,它循环错误的东西?
布尔测试=真;//我的循环从这里开始,我希望能够循环//switch语句,当选择了非案例时,我希望循环在显示错误消息后返回案例1Eclipse 我的循环不断循环,它循环错误的东西?,eclipse,loops,while-loop,switch-statement,boolean,Eclipse,Loops,While Loop,Switch Statement,Boolean,布尔测试=真;//我的循环从这里开始,我希望能够循环//switch语句,当选择了非案例时,我希望循环在显示错误消息后返回案例1 while (test) Proceed = Next.nextInt(); switch (Proceed) { case 1:// Proceed System.out.println("Please enter your 5 digit pin below."); Scanner Pin = new Scanner(
while (test)
Proceed = Next.nextInt();
switch (Proceed) {
case 1:// Proceed
System.out.println("Please enter your 5 digit pin below.");
Scanner Pin = new Scanner(System.in);
int Pincode = Pin.nextInt();
if (Pincode > 9999 && Pincode < 99999) {
System.out.println("1)Display Balance");
System.out.println("2)Withdraw Cash");
System.out.println("3)Other services");
} else {
System.err
.println("Sorry,the pin you enterd was incorrect\nyour card is being ejected\nPlease wait...");
}
test=false;
break;
case 2:// Return Card
System.err.println("Your card is being ejected.\n Please Wait..");
test=false;
break;
default: // i want to display this message and send it back to case 1. when i do the method i'm doing it just keeps spamming this message.
System.err.println("Sorry your request could not be processed.Please re-try");
test=true;
}
while(测试)
继续=Next.nextInt();
开关(继续){
案例1://继续
System.out.println(“请在下面输入您的5位pin”);
扫描仪引脚=新扫描仪(System.in);
int Pincode=Pin.nextInt();
如果(Pincode>9999&&Pincode<99999){
系统输出打印项次(“1)显示余额”);
系统输出打印(“2)提取现金”);
系统输出打印(“3)其他服务”);
}否则{
System.err
.println(“对不起,您输入的pin不正确\n您的卡正在弹出\n请稍候…”);
}
测试=假;
打破
案例2://退货卡
System.err.println(“您的卡正在弹出。\n请稍候…”);
测试=假;
打破
默认值://我想显示此消息并将其发送回案例1。当我使用此方法时,它只会不断垃圾邮件发送此消息。
System.err.println(“抱歉,无法处理您的请求。请重试”);
测试=真;
}
如果要将其发送回案例1,则需要将“继续”设置为1。我猜Next.nextInt()会给你1,2,然后是3,然后是4,等等,超过2的都会进入默认状态;不明白,所以我完全删除了循环,并将继续设置为1?继续=下一步。nextInt();尝试放置调试语句,以便可以看到“继续”设置为什么