この行:
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型にするにはどうすればよいですか?