Using Java Write Program Lets Play Computer Rock Paper Scissors Computer Uses Random Value Q37126063

Using Java, write a program that lets you play the computer inrock paper scissors. The computer uses a random value between 1 and3 to determine its choice of rock, paper, or scissors. The programtakes your input and determines if you have won or lost.

Sample input: 1

Sample output:       The computer’s choice was 3.

      You beat the computer, rock beats scissors.


Solution


import java.util.Scanner;

public class RPS {

   public static void main(String[] args) {
       Scanner sc = newScanner(System.in);
       int you,comp;
       System.out.print(“Enter yourchoice: “);
       you = sc.nextInt();
       comp =(int)(Math.random()*3);
       System.out.println(“The computer’schoice was “+comp);
       if (you==1

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.