java - How do I print an array multiple times? -
my following code else's, able figure out how print correct range, want print range (array) multiple times.
public class lottery { public static void main(string[] args) { int[] lottery = new int[6]; int randomnum; (int = 0; < 6; i++) { randomnum = (int) math.ceil(math.random() * 59); // random number created here. (int x = 0; x < i; x++) { if (lottery[x] == randomnum) // here, code checks if same random number generated before. { randomnum = (int) math.ceil(math.random() * 59);// if random number same, number generated. x = -1; // restart loop } } lottery[i] = randomnum; } (int = 0; < lottery.length; i++) system.out.print(lottery[i] + " "); } }
the output, expected 6 integers in row:
12 52 46 22 7 33
i have unfortunately not been able find directly relevant question. absolute java beginner, please gentle.
the output want follows, each x random number.
x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
technically, i'd last number random number, smaller range. i'll burn bridge time.
do mean this?
for(int j = 0; j< numberoftimetoprint; j++) { (int = 0; < lottery.length; i++) system.out.print(lottery[i] + " "); system.out.print("\n\n"); // 2 line feeds, 1 terminate line , blank }
Comments
Post a Comment