Hey there,
Happy Coding!
Just Don't Give up Yet BUD!
So the code goes something like this that I'm about to provide below, This is something that I Learnt While taking a Java Course from Youtube, I aim to be a Developer Some day!
- The Program gives three chances to the user to play,
- Rock is set as 0, Paper as 1 and Scissor as 2.
- This is checked with the random variable 'a' which for the Random class is imported.
package com.company;
import java.util.Random;
import java.util.Scanner;
public class problemtwo {
public static void main(String[] args) {
Random r = new Random();
Scanner sc = new Scanner(System.in);
int j = 3;
int a = r.nextInt(3);
for(int i =1; i<=j;i++) {
System.out.println("Enter \n0 for Rock\n1 for Paper\n2 for Scissor ");
int b = sc.nextInt();
if (a == b) {
System.out.println("It is a Draw...");
} else if ((b == 0 && a == 2) || (b == 1 && a == 0) || (b == 2 && a == 1)) {
System.out.println("You Win...");
} else {
System.out.println("You Lose...");
System.out.println(a);
}
}
}
}
Comments
Post a Comment