第1个回答 推荐于2019-08-26
你改编一下
public class Prog50{
//定义学号
String[] number = new String[5];
public static void main(String[] args) throws Exception{
Prog50 stud = new Prog50();
stud.input();
stud.output();
}
void input() throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//录入状态标识
boolean isRecord = true;
while(isRecord){
try{
for(int i=0;i<5;i++){
System.out.print("请输入学号:");
number[i] = br.readLine();
isRecord = false;
}catch(NumberFormatException e){
System.out.println("请输入一个数字!");
}
void output() throws IOException{
FileWriter fw = new FileWriter("E://java50//stud.txt");
BufferedWriter bw = new BufferedWriter(fw);
bw.write("No. ");
bw.newLine();
for(int i=0;i<5;i++){
bw.write(number[i]);
}
bw.close();
}
}本回答被网友采纳