java
1 2public class Student { 3 private String number; 4 private String name; 5 private int score; 6 7 Student(String number,String name,int score){ 8 this.number = number; 9 this.name = name; 10 this.score = score; 11 } 12 13 String getNumber() { 14 return number; 15 } 16 17 String getName() { 18 return name; 19 } 20 21 int getScore() { 22 return score; 23 } 24} 25
java
1 2import java.io.BufferedReader; 3import java.io.FileInputStream; 4import java.io.IOException; 5import java.io.InputStreamReader; 6import java.util.Scanner; 7public class Kadai1302 { 8 9 public static void main(String[] args) { 10 Scanner sc = new Scanner(System.in); 11 Student[] arrys = new Student[10]; 12 13 System.out.print("File Name --> "); 14 String FileName = sc.next(); 15 16 try(BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(FileName)))){ 17 String line; 18 int cnt = 0; 19 while((line = reader.readLine()) != null) { 20 String[] fields = line.split(","); 21 String number = fields[0]; 22 String name = fields[1]; 23 int score = Integer.parseInt(fields[2]); 24 arrys[cnt] = new Student(number,name,score); 25 cnt++; 26 } 27 System.out.println("Count : " + cnt); 28 for(int i=0; i<cnt; i++) { 29 System.out.println(arrys[i]); 30 } 31 } catch (IOException e) { 32 e.printStackTrace(); 33 } 34 } 35} 36
回答1件
あなたの回答
tips
プレビュー