我正在为作业编写一个快速的小程序,我想知道是否有人可以告诉我是否有一种方法可以比较多个 int 值并找到彼此匹配的值,例如对或三元组,当然,使用布尔值意味着你是限于两个值。把它放在上下文中,我正在编写一个非常基本的老虎机游戏,看起来像这样:
//the java Random method is the method that will generate the three random numbers
import java.util.Random;
import java.util.Scanner;
public class slotMachine {
public static void main(String[] args) {
//scanner will eventually be used to detect a cue to exit loop
Scanner loopExit = new Scanner(System.in);
int rand1 = (0);
int rand2 = (0);
int rand3 = (0);
Random randGen = new Random();
rand1 = randGen.nextInt(10);
rand2 = randGen.nextInt(10);
rand3 = randGen.nextInt(10);
System.out.print(rand1);
System.out.print(rand2);
System.out.println(rand3);
//this is the part where I need to compare the variables,
//this seems like a slow way of doing it
if ((rand1 == rand2) || (rand2 == rand3))
{
System.out.println("JACKPOT!");
}