java中报错,未定意的标签什么意思?下面是我写的程序;麻烦高人指点,就是outer那!!
发布网友
发布时间:2022-04-30 16:07
我来回答
共2个回答
热心网友
时间:2023-10-08 22:06
你应该放到循环里面,你放到循环外面了
import java.util.*;
class Bank
{
public static void main(String[] args)
{
Clients c[] = new Clients[4];
c[0] = new Clients();
c[1] = new Clients();
c[2] = new Clients();
c[3] = new Clients();
init (c[0],"于淼",1111,1111,10000);
init (c[1],"吕鹏飞",2222,2222,20000);
init (c[2],"张根瑞",3333,3333,30000);
init (c[3],"高原",4444,4444,40000);
System.out.println("**欢迎来到中国建设银行**");
System.out.println("*请输入您的卡号*");
Scanner s = new Scanner(System.in);
int zh = s.nextInt();
int i;
outer:for(i = 0 ; i<4 ; i++)
{
if(zh == c[i].ID)
{
System.out.println("*请输入您的密码*");
Scanner a = new Scanner(System.in);
int mm = a.nextInt();
boolean flag = true;
while(flag)
{
if(mm == c[i].pwd)
{
System.out.println("查看余额请输入1");
System.out.println("存款请输入2");
System.out.println("取款请输入3");
System.out.println("推出请输入0");
Scanner b = new Scanner(System.in);
int shu = b.nextInt();
switch (shu)
{
case 1:
c[i].print();
break;
case 2:
c[i].saveM();
break;
case 3:
c[i].drawM();
break;
case 0:
flag = false;
break;
}
}
else
{
System.out.println("您的密码有误,请重新输入!");
}
}
}
if(i == 4)
{
System.out.println("没有该账号,请重新输入!");
continue outer;
}
}
}
static void init(Clients t,String n,int i,int p,int m)
{
t.name = n;
t.ID = i;
t.pwd = p;
t.money = m;
}
}
class Clients
{
String name;
int ID;
int pwd;
int money;
void print()
{
System.out.println(name+",您的账户余额为"+money+"元.");
}
void saveM()
{
System.out.println("请输入你要储存的金额数:");
Scanner s = new Scanner(System.in);
int m = s.nextInt();
money += m;
}
void drawM()
{
System.out.println("请输入您要取的金额数:");
Scanner s = new Scanner(System.in);
int m = s.nextInt();
if(m > money)
{
System.out.println("您的余额不足");
}
else
{
money -=m;
}
}
}追问你运行了吗?好像不好使,我刚刚重新运行了一下!并且,我想让它重新输入卡号放在哪根本就不对。或者我还有别的方法吗?谢谢了!
热心网友
时间:2023-10-08 22:06
你将 if(i == 4)
{
System.out.println("没有该账号,请重新输入!");
continue outer;
}
这段话放在循环前面执行就行了~
for(i = 0 ; i<4 ; i++)
{
if(i == 4)
{
System.out.println("没有该账号,请重新输入!");
continue outer;
}
if(zh == c[i].ID)
{ ...}
试试看看 程序不报错,但是你的功能实现不了
你的逻辑思路有问题,outer位置不对,而且应该放在一个whlie循环中条件跳出~