Java数组问题
题目2:
定义一个数组,存储1,2,3,4,5,6,7,8,9,10
遍历数组得到的每一个元素,统计数组里面一共多少个能被3整除的数字
package com.school.test;public class test03 {public static void main(String[] args) {int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};int count = 0;for (int i = 0; i < arr.length; i++) {if (arr[i] % 3 ==0 ) {count++;}System.out.println("数组中能被3整除的个数" + count + "个");}}
}
数组【33,5,22,44,55】求最大?
package com.school.practice;public class test03 {public static void main(String[] args) {int[] arr = {33,5,22,44,55};
// 定义maxint max =arr[0];for (int i = 0; i < arr.length; i++) {if(arr[i]>max){max=arr[i];}}System.out.println("最大数值为"+max);}
}
生成10个1~100之间的随机数存入数组。
(1)求出所有数据的和
(2)求所有数据的平均数
(3)统计有多少个数据比平均值小
动态数组