+ 2
How to get switch to check If input is the same as a string?
Scanner scorer = new Scanner(System.in); while (gamePt[p1] != 40 && gamePt[p2] != 40) { System.out.print("Cine a punctat?"); String score = scorer.nextLine(); switch (score) { case "p1": { System.out.println("A inscris p1"); ++p1; System.out.println("Scorul este " + gamePt[p1] + " la " + gamePt[p2]); } case "p2": { //Some code
8 ответов
+ 2
Thanks for the answers
@Gordie: the cases work fine. Eclipse treats them as good. It's the switch that is causing trouble
+ 2
change ur last case to "default:"
+ 1
I have a few days since I started with java, and I don't know what the playground is in eclipse. I will attach the full code. It is for a tennis match. the input should be how scored, in this case with a simple input like p1 or p2. the output of the method should be a number of points added to an int and taken from an array of 0 15 30 40
https://code.sololearn.com/WOzOdCOKQ2aS/?ref=app
+ 1
Thanks, I will try the solution later today and let you know how it went
+ 1
Thanks all for the answers. I removed the brackets and changed the last case into default and it worked