数组简单使用b

 1     public static void main(String[] args) {
 2         Scanner input = new Scanner(System.in);
 3         int[] series = new int[7];
 4         int i;
 5         int sum = 0;
 6         for (i = 0; i < series.length; i++) {
 7             System.out.println("请输入第" + (i + 1) + "个数字:");
 8             series[i] = input.nextInt();
 9         }
10         for (int Series : series) {
11             sum += Series;
12         }
13         System.out.println("数列中所有数字的总和是:" + sum);
14         boolean flag = false;
15         int choice;
16         System.out.println("
请输入您所猜想的数字:");
17         choice = input.nextInt();
18         for (int num : series) {
19             if (choice == num) {
20                 flag = true;
21             }
22         }
23         if (flag == true) {
24             System.out.println("恭喜,您猜对了!!!");
25         } else {
26             System.out.println("很遗憾,您猜错了!!!");
27         }
28 
29     }
原文地址:https://www.cnblogs.com/dark-qinshou/p/4702063.html