i'll start by saying im quite new to Java, ive got reasonable experience in python but Java is fairly new to me.
My problem is that I have created a method to make sure 4 random numbers are all unique to one another, ive done this by just comparing every possible combination using while loops.
I can see that my code works
public static void EqualValues(int num1, int num2, int num3, int num4) {
Random ran = new Random();
while(num1 == num2 || num1 == num3 || num1 == num4) {
num1 = ran.nextInt(9);
num1 += 1;
}
while(num2 == num1 || num2 == num3 || num2 == num4) {
num2 = ran.nextInt(9);
num2 += 1;
}
while(num3 == num1 || num3 == num2 || num3 == num4) {
num3 = ran.nextInt(9);
num3 += 1;
}
while (num4 == num1 || num4 == num2 || num4 == num3) {
num4 = ran.nextInt(9);
num4 += 1;
}
System.out.println(num1);
System.out.println(num2);
System.out.println(num3);
System.out.println(num4);
System.out.println(".........");
}
Which will output 4 unique numbers ie: 2 6 8 4
However, when I do the same in my main method:
public static void main(String[] args) {
Random ran = new Random();
int num1 = ran.nextInt(9);
int num2 = ran.nextInt(9);
int num3 = ran.nextInt(9);
int num4 = ran.nextInt(9);
num1 += 1;
num2 += 1;
num3 += 1;
num4 += 1;
EqualValues(num1, num2, num3, num4);
System.out.println(num1);
System.out.println(num2);
System.out.println(num3);
System.out.println(num4);
}
I get what seems to be the four original numbers before they were checked ie: 2 6 4 4
If someone could point out where i have gone wrong. I hope i have described my question so its easy to understand.