qq_35168308 2016-06-01 07:40 采纳率: 0%
浏览 1143
已采纳

怎样实现这个java程序呢?

我想要把数据写入新建的stu.txt中。该怎样改一下主函数呢?各位大神可以帮忙写个范例吗?

package test0601;public class Student { private String sname; private long sno; private int score1; private int score2; public String getSname() { return sname; } public void setSname(String sname) { this.sname = sname; } public long getSno() { return sno; } public void setSno(long sno) { this.sno = sno; } public int getScore1() { return score1; } public void setScore1(int score1) { this.score1 = score1; } public int getScore2() { return score2; } public void setScore2(int score2) { this.score2 = score2; } }

import java.util.*;public class test { public static void main(String[] args) { Student[] stu = new Student[5]; Scanner s = new Scanner(System.in); for(int i=0;i<5;i++) { stu[i] = new Student(); System.out.printf("请输入第%d名学生姓名: ", i+1); stu[i].setSname(s.nextLine()); System.out.printf("请输入第%d名学生学号: ", i+1); stu[i].setSno(s.nextLong()); System.out.printf("请输入第%d名学生高数成绩: ", i+1); stu[i].setScore1(s.nextInt()); System.out.printf("请输入第%d名学生物理成绩: ", i+1); stu[i].setScore2(s.nextInt()); s.nextLine(); } System.out.printf("所有学生信息:\n"); for(int i=0;i<5;i++) { System.out.printf("%20s%20s%20s%20s\n", "姓名", "学号", "高数", "物理"); System.out.printf("%10s%10s%10s%10s\n", stu[i].getSname(), stu[i].getSno(), stu[i].getScore1(), stu[i].getScore2()); } }}

  • 写回答

2条回答 默认 最新

  • Amy_LLJ 2016-06-01 07:43
    关注

    用输入输出流,写入txt文件,也就是IO的File

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题