Hello I am working through some preparation sheets and one task is to create an array and assign randomly values between 1 and 3 which is working fine, but in the next step we are supposed to also count the amount of 1,2 and 3s.
import javax.swing.JOptionPane;
class Task92{
public static void main(String[] args){
//Task a
int a[] = new int[20];
// Task b
for(int i=0; i<a.length; i++){
a[i] = (int)(1+Math.random()*3);
System.out.println(a[i]);
}
//Task c
int counter[] = new int[3];
for(int i=0; i<a.length; i++);{
if(a[i]==1) {
counter[0]++;
}
else if(a[i]==2) {
counter[1]++;
}
else{
counter[2]++;
}
}
System.out.println("Amound of 1:"+counter[0]+ "\nAmount of 2:"+counter[1]+ "\n Amount of 3:"+counter[2]);
}
}
So the first two Task work well, but when i try to count the amount it is giving me out the error:"cannot find symbol" and points to the a[i] in my if-statements, but I did create my a[] above and assigning values is also working, but accessing the index inside my statement doesn't seem to work. Any ideas what I am doing wrong?
Aucun commentaire:
Enregistrer un commentaire