Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Scanner;
- public class steinSaksPapir {
- Random rand = new Random();
- int randomNumber = rand.nextInt(3) + 1;
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- Random rand = new Random();
- final int ROCK = 1, PAPER = 2, SCISSORS = 3;
- int rps;
- boolean userWins = false;
- boolean programWins= false;
- do {
- rps = rand.nextInt(3) + 1;
- System.out.print("Hva velger du? (Stein/Saks/Papir) ");
- String choice = input.nextLine();
- System.out.print("Programmet valgte ");
- if (rps == ROCK) System.out.println("stein");
- else if (rps == PAPER) System.out.println("papir");
- else if (rps == SCISSORS) System.out.println("saks");
- if(choice.equals("stein")) {
- userWins = rps == SCISSORS;
- programWins = rps == PAPER;
- } else
- if (choice.equals("saks")) {
- userWins = rps == PAPER;
- programWins = rps == ROCK;
- } else
- if (choice.equals("papir")) {
- userWins = rps == ROCK;
- programWins = rps == SCISSORS;
- }
- else {
- System.out.print("Du må velge steinm saks eller papir!");
- choice = input.nextLine();
- }
- }
- while (!userWins && !programWins);
- System.out.print("A winner is ");
- if (userWins) System.out.println("you!");
- else System.out.println("program!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment