我正在使用扫描仪从文本文件中检索。当我尝试从 while 循环外部访问 info1 时,它说变量 info1 可能尚未初始化,但我已经在 while 循环外部初始化了它。如何使用我的代码从 while 循环外部访问它?
String info1,info2,info3,info4,info5,info6,info7;
boolean infoTrue = true;
do{
while(custInfo.hasNext())
{
info1 = custInfo.next();
info2 = custInfo.next();
info3 = custInfo.next();
info4 = custInfo.next();
info5 = custInfo.next();
info6 = custInfo.next();
info7 = custInfo.next();
if(info2== loginID && info3==password)
{
infoTrue=false;
}
}
}while(infoTrue!=false);
System.out.println(info1);
最佳答案
String info1,info2,info3,info4,info5,info6,info7;
上面一行应该是:
String info1="",info2="",info3="",info4="",info5="",info6="",info7="";
关于java - 访问 while 循环变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16253781/