当前位置:网站首页>5. reading and writing of documents (students)
5. reading and writing of documents (students)
2022-06-22 16:18:00 【Xiaomurong】
5 File read and write
Define student class array , Yes N personal (N=5), Including the scores of the top three courses besides name and number of words , Implement file reading and writing of student array .
import java.io.*;
import java.util.Scanner;
public class Student {
final static int N = 5;
private String name;
private int Chinese, English, math;
public Student(String name, int Chinese, int English, int math) {
this.name = name;
this.Chinese = Chinese;
this.math = math;
this.English = English;
}
public static void main(String[] args) {
Student[] stu = new Student[N];
int num = 0;
stu[0] = new Student(" Li 1 white ", 99, 99, 99);
stu[1] = new Student(" Li 2 white ", 89, 89, 90);
stu[2] = new Student(" Li 3 white ", 120, 120, 60);
stu[3] = new Student(" Li 4 white ", 120, 120, 60);
stu[4] = new Student(" Li 5 white ", 120, 120, 60);
File fp = new File("student.txt");
try {
PrintWriter output = new PrintWriter(fp);
for (int i = 0; i<N; i++) {
output.print(stu[i].name + ' ');
output.print(" Chinese language and literature :" + stu[i].Chinese);
output.print(" mathematics :" + stu[i].English);
output.println(" english :" + stu[i].math);
num++;
}
output.close();
} catch (IOException e) {
System.out.println(e.toString());
}
try {
String stus = null;
Scanner input = new Scanner(fp);
for (int i = 0; i < num; i++) {
stus = input.nextLine();
System.out.println(stus);
}
input.close();
} catch (IOException e) {
System.out.println(e.toString());
}
}
}
边栏推荐
猜你喜欢
随机推荐
School enterprise alliance is on the way! Huawei cloud gaussdb has come to universities again
Differences between Oracle client and server
mysql - sql执行过程
ORB_ VI ideological framework
phantomJs使用总结
How to open a futures account? Is it safe to open an online futures account?
odoo本地文档功能开发记录
vector的模拟实现
Trust level of discover
[译文] 弥合开源数据库和数据库业务之间的鸿沟
什么是 SAP ABAP? 类型、ABAP 完整形式和含义
[Shanda conference] definitions of some basic tools
【山大会议】WebRTC基础之对等体连接
Odoo local document function development record
SAP 中的 ABAP 查询教程:SQ01、SQ02、SQ03-017
#进程地址空间
5.文件的读写(学生类)
[Shanda conference] application setting module
ironSource Luna 推出苹果搜索广告限时优惠,注册即享3个月免费服务
Ironsource Luna offers a limited time discount for Apple search ads and enjoys 3 months of free service upon registration








