1 import java.beans.FeatureDescriptor; 2 import java.io.*; 3 import java.util.Scanner; 4 5 6 public class num_3v { 7 public static void main(String[] args) throws IOException { 8 String[] sname = new String[5]; 9 int[] jScore = new int[5]; 10 int[] sScore = new int[5]; 11 File file = new File("e:\\data.txt"); 12 if(! file.exists()) 13 file.createNewFile(); 14 Scanner sc = new Scanner(System.in); 15 FileWriter fw = new FileWriter(file); 16 BufferedWriter bw = new BufferedWriter(fw); 17 for (int i = 0; i < 3; i++) { 18 System.out.println("请输入" + (i + 1) + "同学的姓名:"); 19 sname[i] = sc.next(); 20 System.out.println("请输入" + (i + 1) + "同学的java分数:"); 21 jScore[i] = sc.nextInt(); 22 System.out.println("请输入" + (i + 1) + "同学的数据结构分数:"); 23 sScore[i] = sc.nextInt(); 24 bw.write(sname[i] + "," + jScore[i] + "," + sScore[i] + ","); 25 bw.newLine(); 26 } 27 bw.close(); 28 fw.close(); 29 readDataFromFile(file); 30 } 31 32 private static void readDataFromFile(File file) throws IOException { 33 FileReader fr = new FileReader(file); 34 BufferedReader br = new BufferedReader(fr); 35 String str = ""; 36 int sum = 0; 37 while ((str = br.readLine()) != null) { 38 String[] stuInfo = str.split(","); 39 System.out.println("姓名" + stuInfo[0] + "Java分数:" + stuInfo + "数据结构分数:" + stuInfo[2]); 40 sum = Integer.parseInt(stuInfo[1]) + Integer.parseInt(stuInfo[2]); 41 System.out.println(stuInfo[0] + "的总分是:" + sum); 42 } 43 br.close(); 44 fr.close(); 45 } 46 }
同学成绩
猜你喜欢
转载自www.cnblogs.com/WuYangdan-5201314/p/10954511.html
今日推荐
周排行