0 LIKES LikeUnLike
I have a class that randomly generates 5 numbers between the numbers 1-5. The numbers are placed in an array in the client class. I would like to print out an asterisk (*) that represents the number of times each number was randomly generated. So for 5 numbers if the number 1 was generated once and the number 2 generated 4 times, it would read:1*2****345I have this class:import java.util.Random;public class Rand{ public final int total = 5; private Random rand; public Rand() { rand = new Random(); } public int generate() { return rand.nextInt(total) 1; }}and this client:public class Starcount{ public static void main(String [] args) { Rand random = new Rand(); int [] counter = new int [5]; StringBuffer star = new StringBuffer(); for (int i=1; i <= counter.length; i ) { int myRoll = random.generate(); counter[myRoll-1] ; } for (int i=0; i < counter.length; i ) { System.out.println((i 1) "\t" counter[i]); } }}Any ideas?
Tags:
Report (0) (0) | earlier
Latest activity: earlier. This question has 2 answers.