//求数组中的最大值
public class Teeest {
public static void main(String[] args) {
int [] array4 = {52,1314,13,14,520};
//要定义一个数,但是不能是0,因为数组中可能有负数
int max = array4[0];
//若for里面的i初始值为0,则第一个值自我比较,若为1可省略第一步
for (int i = 1; i < array4.length; i++) {
if(array4[i] > max){
max = array4[i];
}
}
System.out.println(max);
}
}
//求数组中符合要求的值有几个
public class Teeest {
public static void main(String[] args) {
int count = 0;
int[] array2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
for (int i = 0; i < array2.length; i++) {
//if里面是布尔值,若要赋值要写两个等号
if (array2[i] % 3 == 0) {
count++;
}
}
//注意输出打印count语句的位置不要放错了,一定要在for外面
System.out.println(count);
}
}