接受整数并将它们存储在数组中并输出其中最大数的程序。但以下代码不起作用
导入java.util.Scanner;
公共类测试2 {
public static void main(String[] args){
System.out.print("input the array'size : ");
Scanner sc = new Scanner(System.in);
int size = sc.nextInt();
int arr[]=new int[size];
System.out.print("input the array'value :");
for(int i=0; i<size; i++){
int var = sc.nextInt();
arr[i] = var;
}
System.out.print("inputed value: ");
for(int i=0; i<size; i++) {
System.out.print(arr[i]+ " ");
}
int max = 0;
for(int j=0; j<size; j++){
if(max<arr[j+1]){
max = arr[j];
}
else {
continue;
}
}
System.out.println("the largest number in array :"+ max);
}
}
POPMUISE
相关分类