heather473
Technical User
Can someone please explain the loop process to me so I can figure out why the loop isn't working in my program.
Thanks
import cs1.Keyboard;
public class Slots2
{
//-----------------------------------------------------------------
// Plays a Slot Machine game with the user.
//-----------------------------------------------------------------
public static void main (String[] args)
{
final int MAX = 9;
int Num1, Num2, Num3;
String another = ("n"
;
System.out.print (" Would you like to play"
;
another = Keyboard.readString();
{
while (another == ("n"
);
Num1 = (int) (Math.random() * MAX) + 1;
Num2 = (int) (Math.random() * MAX) + 1;
Num3 = (int) (Math.random() * MAX) + 1;
System.out.print (Num1);
System.out.print (Num2);
System.out.println (Num3);
{
if (Num1==Num2)
if (Num2==Num3)
System.out.println ("You win!"
;
else
System.out.println ("Sorry, You Lose."
;
else
System.out.println ("Sorry, You Lost."
;
System.out.println ("Would you like to play again(y/n)?"
;
another = Keyboard.readString();
}
}
{
System.out.println ("Thank you, Have a good day!"
;
}
}
}
Thanks
import cs1.Keyboard;
public class Slots2
{
//-----------------------------------------------------------------
// Plays a Slot Machine game with the user.
//-----------------------------------------------------------------
public static void main (String[] args)
{
final int MAX = 9;
int Num1, Num2, Num3;
String another = ("n"
System.out.print (" Would you like to play"
another = Keyboard.readString();
{
while (another == ("n"
Num1 = (int) (Math.random() * MAX) + 1;
Num2 = (int) (Math.random() * MAX) + 1;
Num3 = (int) (Math.random() * MAX) + 1;
System.out.print (Num1);
System.out.print (Num2);
System.out.println (Num3);
{
if (Num1==Num2)
if (Num2==Num3)
System.out.println ("You win!"
else
System.out.println ("Sorry, You Lose."
else
System.out.println ("Sorry, You Lost."
System.out.println ("Would you like to play again(y/n)?"
another = Keyboard.readString();
}
}
{
System.out.println ("Thank you, Have a good day!"
}
}
}