Write a program to generate 100 random integers between 0 an

Write a program to generate 100 random integers between 0 and 9, and display the count for each number, like how many 2s, and how many 5s, etc. You can use (int) (Math random()*10) to generate random integers .

Solution


public class randomCount {
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       int[] count = new int[11];
       for(int i=0;i<11;i++)
       {
           count[i]=0;
       }
       for(int i=0;i<100;i++)
       {
           count[(int)(Math.random()*10)]++;
       }
       for(int i=0;i<10;i++)
       {
           System.out.println(\"The number of \"+i+\"\'s is \"+count[i]);
       }
   }

}

 Write a program to generate 100 random integers between 0 and 9, and display the count for each number, like how many 2s, and how many 5s, etc. You can use (in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site