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)




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

7 Years
Discussion Span
Last Post by Xufyan

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!!

Edited by Xufyan: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.