Rock - / * / Rock.java / / Play Rock, Paper, Scissors with...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// **************************************************************** // Rock.java // // Play Rock, Paper, Scissors with the user // // **************************************************************** import java.util.Scanner; import java.util.Random; public class Rock { public static void main(String[] args){ String personPlay; //User's play -- "R", "P", or "S" String computerPlay; //Computer's play -- "R", "P", or "S" int computerInt; //Randomly generated number used to determine //computer's play Random generator = new Random(); Scanner scan = new Scanner (System.in); //Get player's play -- note that this is stored as a string System.out.print ("Enter your play: R, P, or S: "); personPlay = scan.nextLine(); //Make player's play uppercase for ease of comparison personPlay = personPlay.toUpperCase(); //Generate computer's play (0,1,2) computerInt = generator.nextInt(3); //Translate computer's randomly generated play to string //"R", "P", or "S". If play is not a value you expected (0,1,2),
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/22/2010 for the course CS 202 taught by Professor Fong during the Spring '10 term at SIU Carbondale.

Page1 / 2

Rock - / * / Rock.java / / Play Rock, Paper, Scissors with...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online