For my code I would like to check an array which will be filled many times with 6 random integers. Each time I want to check if all 6 values are different and if this happens for the code to stop. However after trying to use loops I was having problems so I just used a long ass If statement to check each location in the array with each other location. However This is not working. Would love if someone could tell me why i'm being stupid.
if((diceArray[0] != diceArray[1] & diceArray[0]!=diceArray[2] & diceArray[0]!=diceArray[3] & diceArray[0]!=diceArray[4] & diceArray[0]!=diceArray[5] & diceArray[1]!=diceArray[2] & diceArray[1]!=diceArray[3] & diceArray[1]!=diceArray[4] & diceArray[1]!=diceArray[5] & diceArray[2]!=diceArray[3] & diceArray[2]!=diceArray[4] & diceArray[2]!=diceArray[5] & diceArray[3]!=diceArray[4] & diceArray[3]!=diceArray[5] & diceArray[4]!=diceArray[5]))
{
System.out.println("stop babes");
}
else
{
System.out.print("Did not work");
}
There is more to this code but I know the rest works as when I print out each sequence they all pint out no problem. When I run the code with this part Ideally It would print out many sequences with duplicate number and with these print out "did not work" and one of the results should come out with "stop babes" (These will be removed later just using them to test and a return used to stop the code) However when i run the code this happens
how many rolls of 6 dice? 3
LINE 1
4 1 3 5 5 5
stop babes
LINE 2
4 4 1 2 6 1
stop babes
LINE 3
3 6 4 6 4 4
stop babes
JUST a quick edit re on the if statement. I realise It could be shortened to a quick loop I just wanted to brute force the problem. The main problem is the text "stop babes" should only be printing when a code such as 1 2 3 4 5 6 is printed informing me the code works and allowing me to insert a break statement on the main FOR loop.
&is a valid Boolean/logical operator; it just doesn't short-circuit like&&does.&&, so you should use that. There are better approaches to your problem, though.