Array Elements as Counters
CODE
import java.util.Random;
public class red {
public static void main (String args[]) {
Random rand = new Random();
int bucky[] = new int[7];
//yaha ek cheez note karo for loop mein jo counter int use kiya hai uska use nhi kiya hai andar yaani yaha bas itna hi ki loop ko kitni baar chalana ha
for(int counter =0; counter<1000;counter++) {
++bucky[1+rand.nextInt(6)]; // yaha ++ ka matlab hai ki bucky[x] ki value 1 se add kardo
}
for(int i=1;i<bucky.length;i++) {
System.out.println(bucky[i]);
}
}
}
Comments
Post a Comment