JAVA CODE FOR ROCK PAPER SCISSOR GAME
import java.util.Random;
import java.util.Scanner;
public class rock_paper_scissor {
public static void main(String[] args) {
System.out.println("THIS IS A ROCK PAPER SCISSOR GAME : ");
Scanner sc = new Scanner(System.in);
int n=0;
Random random = new Random();
do
{
int a =random.nextInt(3);
char c;
char ch ='R';
switch(a){
case 0:
ch = 'R';
break;
case 1:
ch = 'P';
break;
case 2:
ch = 'S';
break;
}
c=ch;
System.out.println("Type R for rock , P for paper , S for scissor ");
char b = sc.next().charAt(0);
System.out.println(c);
if (c=='R'&&b=='S'||c=='R'&&b=='S'||c=='S'&&b=='P')
System.out.println("you loose hahahaha");
else if (c=='R'&&b=='P'||c=='S'&&b=='R'||c=='P'&&b=='S')
System.out.println("you won hehehe");
else
System.out.println("Draw:(");
n++;
}while(n<5);
}
}
Comments
Post a Comment