I need to make a random lottery generator for class with a boolean array. at first i made it with an int array and it worked perfectly fine but when i changed the int array to a bool array i got an error that says "Type mismatch: cannot convert from int to boolean". I'm wondering how to fix my code so this will work.
int highestNumber, numsInLottery, randomNum;
//int[] lottery = new int[numsInLottery];
System.out.println("Welcome to the Lottery Number Generator!");
System.out.println("How many numbers are in your lottery?");
numsInLottery = TextIO.getInt();
System.out.println("What is the highest number in your lottery?");
highestNumber = TextIO.getInt();
boolean[] lottery = new boolean[numsInLottery];
for(int i = 0; i < numsInLottery; i++)
{
randomNum = (int)(Math.random() * highestNumber);
for(int x = 0; x < i; x++ )
{
/*if (lottery[x] == randomNum)
{
randomNum = (int)(Math.random() * highestNumber);
x = -1;
}*/
}
lottery[i] = randomNum;
System.out.print(lottery[i] + " ");
}
//System.out.print(lottery[i] + " ");
}
}
Aucun commentaire:
Enregistrer un commentaire