这一行:
arr[i] = sc.nextDouble();
从此代码:
public class z01 {
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
System.out.println("Enter array size: ");
int n = sc.nextInt();
double[] arr = new double[n];
double min = 0;
for(double i = 0; i <n; i++){
System.out.println("Enter element " + (i + 1));
arr[i] = sc.nextDouble();
if(i%3 == 0 && i <= min){
min = i;
}
}
if(min != 0){
System.out.println("The smallest number divisible by 3 is" + min);
} else {
System.out.println("No number is divisible by 3");
}
}
}
给出这个警告:
Type mismatch: cannot convert from double to int
如何使 java 中的用户输入为 double 类型?