I am scanning a file of numbers into a datatype double array and am getting a type mismatch for my "score" and "i" variables that i have both already declared doubles.
static double[]convert(String file){
try {
File ar = new File(file);
Scanner sc = new Scanner(file);
double score = 0;
while(sc.hasNextDouble()) {
score++;
sc.nextDouble();
}
double[]stat= new double[score];
for(double i=0;i<stat.length;i++) {
stat[i]= sc.nextDouble();
}
return stat;
}
catch (Exception e) {
return null;}
}
return stat;
should be after the for loop not inside itdouble[] stat = new double[score];
is wrong, you should try double[] stat = new double[(int)score];
instead or make the variable called score
of type int
stat[i]= sc.nextDouble();
is wrong because you made the variable i
of type double, so instead of for(double i=0;i<stat.length;i++)
, you should try for(int i=0;i<stat.length;i++)
as imagine if the variable i = 2.5
, there is nothing called arr[2.5]
.