当前位置:网站首页>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());
}
}
}
边栏推荐
- [Shanda conference] peer connection based on webrtc
- C language learning -17- function is passed in as a parameter
- Pymssql Module User Guide
- SAP ABAP 中的 Smart Forms-014
- Simulation of stack and queue
- Program substitution function
- Mysql触发器
- GD32F4xx MCU 驱动mcp2515扩展CAN接口
- [Shangshui Shuo series] day three - VIDEO
- Dear students, don't read the textbooks any more. Just read this one for the complexity of time
猜你喜欢

Gbase "library" special training of innovation and application Committee of Beijing fintech Industry Alliance

10款超牛Vim插件,爱不释手了

SAP ABAP 中的用户出口和客户出口-015

SAP ABAP 对话框编程教程:中的模块池-09

Make the text template in pycharm project support jinjia2 syntax

Cross border integration, creativity and innovation to help improve the influence of cultural tourism night tour

Program substitution function

webDriver以及Selenium使用总结

wallys/WiFi6 MiniPCIe Module 2T2R 2×2.4GHz 2x5GHz

uni开发微信小程序自定义相机自动检测(人像+身份证)
随机推荐
小程序开发----自定义有效期缓存
ORB_ VI ideological framework
【一起上水硕系列】Day Three - video
Quick sort_ sort
阿里云中间件的开源往事
SAP ABAP 数据字典教程 SE11:表、锁定对象、视图和结构 -03
[Huawei cloud to Jian Zhiyuan] the winning list of essay solicitation is released!
Uni develops wechat applet to customize automatic camera detection (portrait + ID card)
数字人民币可以买理财产品了!建行APP在试点地区上线服务专区,实测体验如何?
[Shanda conference] establishment of webrtc tools for multi person video call
The odoo system sets priorities for the views independently developed by the original model
How to open a futures account? Is it safe to open an online futures account?
Wechat applet avatar pendant production
使用 zipfile、openpyxl、flask 批量导出excel zip
Scala language learning-05-a comparison of the efficiency of recursion and tail recursion
wallys/WiFi6 MiniPCIe Module 2T2R 2×2.4GHz 2x5GHz
SAP web service 无法使用 SOAMANAGER 登陆到SOA管理页面
stack和queue的模拟实现
各位学弟学妹,别再看教材了,时间复杂度看这篇就好了
10款超牛Vim插件,爱不释手了