package com.itheima; public class arraytrain { public static void main(String[] args) { //定义一个数组里面存1,2,3,4,5 求和 int[] num = new int[]{1,2,3,4,5}; int sum = 0; for (int i = 0; i < num.length; i++) { System.out.println(num[i]); sum = sum + num[i]; } System.out.println(sum); System.out.println("-----------------------------------------"); //定义一个数组存1,2,3,4,5,6,7,8,9,10 求有多少个能被3整除 int count = 0; int[] arr1 = new int[10]; for (int t = 1; t <= 10; t++) { arr1[t-1] = t; if(t % 3 == 0) count++; } System.out.println(count); System.out.println("-----------------------------------------"); //定义一 个数组 存1,2,3,4,5,6,7,8,9,10 //要求:1.奇数就扩大两倍 2.偶数就缩小两倍 int[] arr2 = new int[10]; for (int k = 1; k <= 10; k++) { arr2[k-1] = k; System.out.println(arr2[k-1]); if(arr2[k-1] % 2 == 0){ arr2[k-1] /= 2; } else{ arr2[k-1] *=2; } System.out.println(arr2[k-1]); } } }