62,628
社区成员
发帖
与我相关
我的任务
分享 print("请输入学生信息,如:Grooter 201610098237 男 计算机工程学院 4)");
while(true) {
s.nextLine();
String stuInfo=s.nextLine();
if(stuInfo.equals("end")) {
break;
}
String[] str=null;
try {
//报数组越界异常
str=stuInfo.split(" ");
}catch(Exception e) {
println("输入错误,请重新输入");
}
try {
//也包数组越界异常
if(str.length!=5) {
println("输入错误,请重新输入");
}
}catch(Exception e) {
println("输入错误,请重新输入");
}
Student student=new Student(str[0],str[1],str[2],str[3],str[4]);
student.write();
}class Test {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("请输入学生信息,如:Grooter 201610098237 男 计算机工程学院 4)");
while (true) {
//s.nextLine();
String stuInfo = s.nextLine();
if (stuInfo.equals("end")) {
break;
}
String[] str = null;
try {
str = stuInfo.split(" ");
System.out.println(str);
} catch (Exception e) {
System.out.println("输入错误,请重新输入1");
}
try {
if (str.length != 5) {
System.out.println("输入错误,请重新输入2");
}
} catch (Exception e) {
System.out.println("输入错误,请重新输入3");
}
}
}
}