System.out.print("Enter your play (R, P, S): ");
personPlay=Keyboard.readString();
//Use a method of the String class to make the personPlay all UPPERCASE
personPlay.toUpperCase();
//Use Math.random() to generate computer's play as either 0, 1 or 2
//Store result in computerInt
computerInt=(int)Math.random()*3;
//Use else-if to convert 0, 1 or 2 to initialize computerPlay to R, P or S
if(computerInt==0)
computerPlay="R";
else
{ if(computerInt==1)
computerPlay="P";
if(computerInt==2)
computerPlay="S";
}
System.out.println("The computer played: " + computerPlay);
/*-------------------------------------------------------
every time i compile and run the program, it always outputs "The computer played: R" ....so there is something wrong with my if-else statements, but i can't figure out what?
2007-12-09
10:36:21
·
5 answers
·
asked by
hahahahahaha
1
in
Computers & Internet
➔ Programming & Design
Believe it or not-- I have studied java code and understand how Math.random works....
2007-12-09
11:44:56 ·
update #1