write a program that playsthe popular scissor-rock-paper game. The p rogram rand
ID: 3609036 • Letter: W
Question
write a program that playsthe popular scissor-rock-paper game. The p rogram randomlygenerates a number 0,1,2 representing scissor rock paper. Theprogram prompts a user to display a message indicating whether theuser or the computer wins or draws.This is my code and it isn't coming out correctly. could someonehelp me to figure out what is wrong with it. Thanks will ratelifesaver for working code.
import java.util.*;
public class rpsgame
{
public static void main(String[] args)
{
Scanner in = newScanner(System.in);
int num;
String yorn;
Random gen = newRandom();
do
{
num =gen.nextInt(3);
if(num==0)
System.out.println("computer plays rock");
else
if(num==1)
System.out.println("computerplays scissor");
else
if(num==2)
System.out.println("computer plays paper");
System.out.println("Enter who wins: 1-computer 2-human");
System.out.println("Play again? (Y/N)");
yorn=in.next();
yorn=yorn.toUpperCase();
}
while(yorn.charAt(0)=='Y');
}
}
this is the output it gives me......which is not correct, you maywant to run it as well if you want.
computer plays scissor
Enter who wins:
1-computer
2-human
Play again? (Y/N)
Explanation / Answer
please rate - thanks The red line was missing-should have messaged me! import java.util.*; public class rockpaperscissor { public static void main(String[]args) {Scanner in = newScanner(System.in); int num ; String yorn; Random gen = newRandom(); do{ num=gen.nextInt(3)+1; if(num==1) System.out.println("computer plays rock"); else if(num==2) System.out.println("computer plays paper"); else System.out.println("computer playsscissor"); System.out.println("Enter whowins: 1 - computer 2 - human"); num=in.nextInt(); System.out.println("Play again?(Y/N)"); yorn=in.next(); yorn=yorn.toUpperCase(); }while(yorn.charAt(0)=='Y'); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.