public class App {
public static void main( String[] args ) {
int[] set = {0,0,0,0,0,0,0};
for(int i = 0; i < 7; i++) {
boolean unique = false;
while (!unique) {
int j = 0;
try {
j = JRandom.randInt(1, 45);
}
catch (ParamterException e) {
e.printStackTrace();
}
unique = true;
for(int k = 0 ; k < 7; k++) {
if (j==set [k]) {
unique = false;
break;
}
}
if (unique) {
set [i] = j;
}
}
}
for (int i= 0; i < 6; i++) {
if (i == 5) {
System.out.println(set[i]);
}
else {
System.out.print(set[i]+", ");
}
}
System.out.println("Bonus Ball = " + set[6]);
}
}
I was wondering how I would implement bubble-sort into this code. It works on my machine and produces 6 random numbers + a bonus ball.
2, 34, 25, 14, 39, 13
Bonus Ball = 30
I was aiming to make it print so the numbers are ascending so that it would be like the lotto, the idea anyway.
That's all, thanks.