Ok so I'm doing some practice questions, and this one is trippin me up a bit. I need to create an array that stores data 0.0, 0.1, 0.2, 0.3, all the way to 20.0. Then I have to compute the sums of the elements that are not integers (i.e 0.0, 1.0, 2.0, 3.0...onward to 20.0).
this is what I have come up with so far...but I am unsure if this is truly the most efficient way or even entirely correct. suggestions/help greatly appreciated! our class textbook is entirely out of date and useless
class Test1{
public static void main(String[] args){
double[] array = new double[201];
for (int i = 0; i <= 200; i++){
array[i] = i/10.0;
//System.out.println(array[i]);
}
int sum = 0;
sum = 0;
for (int i = 0; i < array.length; i++){
if(array[i]!=(int)(array[i])){//array[i]is not int
sum += array[i];
}
}
System.out.print(sum);
}
}