티스토리 뷰
각 점수의 최대값과 최소값 출력
DataEx.java
import java.util.Arrays;
public class DataEx {
public static void main(String[] args) {
// TODO Auto-generated method stub
Data data = new Data("분석 데이터 url");
data.ReadData();
}
}
Data.java
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Data {
String url = "";
int i = 0;
int[][] scores = new int[15][];
Data(String url) {
this.url = url;
}
void ReadData() {
try {
FileReader fr = new FileReader(url);
BufferedReader br = new BufferedReader(fr);
String line = "";
br.readLine();
int maxScore[] = new int[3];
int minScore[] = new int[3];
while ((line = br.readLine()) != null) {
String[] sArr = line.split(","); //index 날리기 (국어, 수학, 영어...)
scores[i] = new int[sArr.length];
for (int j = 0; j < sArr.length; j++) { //배열 scores에 데이터 저장
scores[i][j] = Integer.parseInt(line.split(",")[j]);
System.out.print(scores[i][j] + "\t");
if(i==0 && j>0) { //maxScore[0]와 minScore[0]에 초기값 지정
maxScore[j-1] = Integer.parseInt(line.split(",")[j]);
minScore[j-1] = Integer.parseInt(line.split(",")[j]);
}
if(i>0 && j>0) { //maxScore[0]와 minScore[0]가 아닌 경우, 최대값 최소값 알고리즘 실행
if(maxScore[j-1]<scores[i][j])
maxScore[j-1] = scores[i][j];
if(minScore[j-1] > scores[i][j])
minScore[j-1] = scores[i][j];
}
}
System.out.println();
i++;
}
//max값 출력
System.out.println("===================================================");
System.out.print("MAX:\t");
for(int i=0; i<maxScore.length; i++) {
System.out.print(maxScore[i]+"\t");
}
//min값 출력
System.out.println();
System.out.print("MIN:\t");
for(int i=0; i<minScore.length; i++) {
System.out.print(minScore[i]+"\t");
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("FileNotFound");
} catch (IOException e) {
System.out.println("IOException");
}
}
}
분석 데이터