★★ Java の宿題ここで答えます Part 54 ★★
780 :
デフォルトの名無しさん:
772の課題2
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;
public class Kadai772_2 {
public static void main(String[] args) throws Exception {
TreeSet ts = new TreeSet();
int data = 0;
int count = 1;
while ((data = inputData(count)) != 666) {
ts.add(new Integer(data));
count++;
}
Integer[] datas = (Integer[]) ts.toArray(new Integer[ts.size()]);
System.out.println("データの入力数=" + datas.length);
System.out.println("最大値=" + datas[datas.length - 1]);
}
private static int inputData(int count) throws IOException {
System.out.print(count + "人目のデータ=");
String data = new BufferedReader(new InputStreamReader(System.in))
.readLine();
return Integer.parseInt(data);
}
}