I want to generate random numbers, display them with ten in a row, and count how many are 1s, 2s, 3s, 4s, 5s, and 6s with nested if/else statement.

import java.util.Random;
public static void main(String [] args)

{

    Random generator = new Random( );  
    int value = 0;
    int numbers1 = 0; 
    int numbers2 = 0; 
    int numbers3 = 0; 
    int numbers4 = 0; 
    int numbers5 = 0; 
    int numbers6 = 0;

    for (int counter=0; counter<20; counter++)
    {
      int value = generator.nextInt(6)+1;
      System.out.print("  "+value);

      if (counter % 10 == 0)
      {
        
      System.out.print(); 

      }

    }

}

Please identify any mistakes and help me with the counting of random numbers.

Use Math.random() to generate random numbers,
create an integer array with 1 row and 6 column !
set each value in array to 0,
Switch the random number use 6 cases (1,2,3,4,5,6)
if random number equals to 1 then increment to the first position of Array
if random number equals to 2, increment to the 2nd position of Array and so on!

this is even more simpler!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.