0

Java: Import small programm wont work in Code Playground

Hey, im a Java beginner and wrote a small RPS game, which I wanted to share here. When I Copy Paste the Code here, my Scanner Inputs are not working as on my local console. (The playground asks me instant for the User Input instead of waiting for the first coderows to be executed) Can you guys tell me what I should change? BR Kevin

19th Feb 2019, 10:53 AM
Kevin Kleckner
Kevin Kleckner - avatar
1 Antwort
0
//Rock_Paper_Scissor Game import java.util.Scanner; import java.util.Random; public class Game { public static void main (String[] args){ //While input has to be outside the do loop String input = null; Scanner scan = new Scanner(System.in); //do - whille loop for restarting ability do { //Introtext //Cleanup for Console output //System.out.print("\033[H\033[2J"); //System.out.flush(); System.out.println("Hey!"+"\n"+"What do you pick:"+"\n"+"\n"+"1. Rock"+"\n"+"2. Paper"+"\n"+"3. Scissor"); //random Opponent value Random rand = new Random(); int o = rand.nextInt(3)+1; //Scannerinput System.out.println("\n"+"Press 1, 2 or 3 and hit Enter"+"\n"); System.out.print("Your input: "); //print instead of println for seeing the scanner input in the same line int i = scan.nextInt(); System.out.println("____________________"); //Start Game and check if input is valid while (i <= 0 || i > 3){ System.out.println("Try again!"+"\n"+"Please Enter a valid number!"); i = scan.nextInt(); System.out.println("____________________"); } //Values 1. Rock if (i == 1 && o == 1){ System.out.println("Rock ties Rock"+"\n"+">>>Maybe next time<<<"); } else if (i == 1 && o == 2){ System.out.println("Paper wraps Rock"+"\n"+">>>You loose<<<"); } else if (i == 1 && o == 3){ System.out.println("Rock crushes Scissor"+"\n"+">>>You win<<<"); } //Values 2. Paper if (i == 2 && o == 1){ System.out.println("Paper wraps Rock"+"\n"+">>>You win<<<"); } else if (i == 2 && o == 2){ System.out.println("Paper t
19th Feb 2019, 10:53 AM
Kevin Kleckner
Kevin Kleckner - avatar