IT/Java

자바 list, vector, generec

노마드오브 2018. 7. 31. 21:00

package test;


import java.util.List;

import java.util.Scanner;

import java.util.Vector;



public class Test1 {


public static void main(String[] args) {


List<Integer> rainlist = new Vector<>(); 

Scanner scanner = new Scanner(System.in);

while (true) {

System.out.println("강수량 입력 (0 입력시 종료) >> ");

int num = scanner.nextInt();


if (num == 0) {

System.out.println("종료합니다");

break;

int sum = 0;

rainlist.add(num);

for (int i=0; i<rainlist.size(); i++) {

System.out.print(rainlist.get(i) + " ");

sum += rainlist.get(i);

}

System.out.println();

System.out.println("현재평균 " + sum/rainlist.size());

}

scanner.close();

}


}