public String roll()
{
Random generate = new Random();
int diceRoll;
int firstNum;
int secondNum;
boolean winner = false;
for (int x=1; x<=3; x++)
{
firstNum = generate.nextInt(6)+1;
secondNum = generate.nextInt(6)+1;
diceRoll = firstNum + secondNum;
System.out.println("Roll number " + x + " was " + diceRoll);
if(userNum == diceRoll)
{
winner = true;
break;
}
}
if(winner)
{
System.out.println("\nYou win!! Congratulations");
}
else
{
System.out.println("\nYou lose");
}
return roll;
}
When I run This class on my driver class at the end of the whole loop I get my numbers and all but I also get the word null at the end.
Just like this:
Roll number 1 was 6
Roll number 2 was 8
Roll number 3 was 2
You win!! Congratulations
null