Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package stensax;
- import java.util.Random;
- import java.util.Scanner;
- public class Stensax {
- private static Object user_input;
- public static void main(String[] args) {
- Random random = new Random();
- Scanner scanner = new Scanner(System.in);
- int userChoice, computerChoice;
- String WantToPlay = "Y";
- while ( "Y".equals(WantToPlay)){
- System.out.println("Välj!(0 = Sten; 1 = Påse; 2 = Sax):");
- userChoice = scanner.nextInt();
- if(userChoice < 0 || userChoice > 2)
- {
- System.out.println("Fel Alternativ. Avslutar Programmet.");
- System.exit(0);
- }
- computerChoice = random.nextInt(3);
- if(userChoice == computerChoice)
- {
- if(userChoice == 0)
- {
- System.out.println("Båda spelarna valde sten!");
- }
- else if (userChoice == 1)
- {
- System.out.println("Båda spelarna valde påse!");
- }
- else
- {
- System.out.println("Båda spelarna valde sax!");
- }
- System.exit(0);
- }
- if(userChoice == 0)
- {
- if(computerChoice == 1)
- {
- System.out.println("Du valde sten; Datorn valde påse");
- System.out.println("Datorn vann!");
- }
- else
- {
- System.out.println("Du valde sten; Datorn valde sax");
- System.out.println("Du vann!");
- }
- }
- else if(userChoice == 1)
- {
- if(computerChoice == 0)
- {
- System.out.println("Du valde påse; Datorn valde sten");
- System.out.println("Du vann!");
- }
- else
- {
- System.out.println("Du valde påse; Datorn valde sax");
- System.out.println("Datorn vann!");
- }
- }
- else
- {
- if(computerChoice == 0)
- {
- System.out.println("Du valde sax; Datorn valde sten");
- System.out.println("Datorn vann!");
- }
- else
- {
- System.out.println("Du valde sax; Datorn valde påse");
- System.out.println("Du vann!");
- }
- }
- System.out.print("Continue Y/N?");
- }scanner.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement