标签:之一 arraylist 结束 data next 格式 [] scanner for
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); List<Integer> arr = new ArrayList<Integer>(); int num; while (in.hasNext()) { num = in.nextInt(); arr.add(num); if (num == 0) { in.close(); break; } } int count = 0; int grade = 0; for (int i = 0; i < arr.size(); i++) { if (arr.get(i) == 1) { count = 0; grade += 1; } else if (arr.get(i) == 2) { count += 2; grade += count; } else { break; } } System.out.println(grade); } }
标签:之一 arraylist 结束 data next 格式 [] scanner for
原文地址:https://www.cnblogs.com/NEU-2015/p/9332877.html