Monday 18 May 2020

LET'S PLAY SCISSOR-ROCK-PAPER GAME USING JAVA LANGUAGE

Q-39-  Write a java program that plays the popular scissor-rock-paper game. (A scissor can cut a paper, a rock can knock a scissor, and a paper can wrap a rock.) The program randomly generates a number 0, 1, or 2 representing scissor, rock, and paper. The program prompts the user to enter a number 0, 1, or 2 and displays a message indicating whether the user or the computer wins, loses, or draws.

INPUT :

import java.util.Scanner;

public class NCM {

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int num;
int random=(int)( Math.random()*(3));
System.out.println("Here scissor=0 ,rock=1 ,paper=2");
System.out.println("Enter Your Choice :");
num=sc.nextInt();
if(num==0 && random==0)
{
System.out.println("Computer Is Scissor And You Are Scissor.");
System.out.println("This Match Is Draw .");
}
else if(num==0 && random==1)
{
System.out.println("Computer Is Rock And You Are Scissor.");
System.out.println("Computer Won The Match.");
}
else if(num==0 && random==2)
{
System.out.println("Computer Is Paper And You Are Scissor.");
System.out.println("You Won The Match .");
}

else if(num==1 && random==0)
{
System.out.println("Computer Is Scissor And You Are Rock.");
System.out.println("You Won The Match .");
}
else if(num==1 && random==1)
{
System.out.println("Computer Is Rock And You Are Rock.");
System.out.println("This Match Is Draw .");
}
else if(num==1 && random==2)
{
System.out.println("Computer Is Paper And You Are Rock.");
System.out.println("Computer Won The Match .");
}
else if(num==2 && random==0)
{
System.out.println("Computer Is Scissor And You Are Paper.");
System.out.println("Computer Won The Match .");
}
else if(num==2 && random==1)
{
System.out.println("Computer Is Rock And You Are Paper.");
System.out.println("You Won The Match.");
}
else if(num==2 && random==2)
{
System.out.println("Computer Is Paper And You Are Paper.");
System.out.println("This Match Is Draw .");
}
else
{
System.out.println("You Have Entered Wrong Value .");
}

}

}

OUTPUT :

Here scissor=0 ,rock=1 ,paper=2
Enter Your Choice :
0
Computer Is Scissor And You Are Scissor.
This Match Is Draw .

Here scissor=0 ,rock=1 ,paper=2
Enter Your Choice :
1
Computer Is Paper And You Are Rock.
Computer Won The Match .

Here scissor=0 ,rock=1 ,paper=2
Enter Your Choice :
2
Computer Is Rock And You Are Paper.
You Won The Match.



No comments:

Post a Comment