【发布时间】:2016-11-05 04:13:55
【问题描述】:
我刚刚制作了这个简单的学生程序,它读取数据并写入文件。
我需要的是,如果我想输入 100 个学生的数据,如何将其放入列表中,并且应该来自用户端
例如,
输入你想输入的学生:2
姓名:Satish devnani 卷号:1
姓名:索努 卷数:2
如果用户输入 100,那么它应该是 100。
到此为止:
import java.util.*;
import java.io.*;
class filesatish2{
String name;
int number;
//int i=0;
public static void main(String args[]) throws IOException {
//int i;
filesatish2 stname= new filesatish2();
Students.READ();
Students.FILEWRITE();
}
int HOWMANY()
{
int count;
Scanner sc=new Scanner(System.in);
printit("How many data you want to enter ?");
count=sc.nextInt();
//printit(""+count);
return count;
}
void READ()
{
Scanner sc=new Scanner(System.in);
Scanner text=new Scanner(System.in);
printit("Name :");
name=text.nextLine();
printit("Number :");
number=sc.nextInt();
}
public static void printit(String a)
{
System.out.print(a);
}
public void FILEWRITE() throws IOException
{
File student = new File("Student.txt");
FileWriter printer = new FileWriter(student);
student.createNewFile();
printer.write(""+name);
printer.write("\t"+number);
printer.flush();
printer.close();
}
}
【问题讨论】: