Reputation: 3898
For most of you, this will be very simple, but I'm a newbie- so don't hate too much! Ok, so I have two arrays, one showing 'correct scores' and another showing 'incorrect scores'. I want to create a new array using these which shows the % correct.
I have written :
int[] correct1 = {20, 20, 13, 15, 22, 18, 19, 21, 23, 25};
int[] incorrect1 = {2, 1, 5, 2, 2, 5, 8, 1, 0, 0, 1};
for(int a = 0; a < correct1.length; a++ ){
int[] percentage1 = ((correct1[a] / (correct1[a] + incorrect1[a]))*100);
}
But this gives me a type mismatch between int and int[]. Any help would be appreciated, thanks.
Upvotes: 1
Views: 1076
Reputation: 12843
for(int a = 0; a < correct1.length; a++ ){
int[] percentage1 = ((correct1[a] / (correct1[a] + incorrect1[a]))*100);
}
Above should be:
double[] percentage1 = new double[correct1.length];
for(int a = 0; a < correct1.length; a++ ){
percentage1[a] = (double)((correct1[a] / (correct1[a] + incorrect1[a]))*100);
}
Upvotes: 4