Note that there are some explanatory texts on larger screens.

plurals
  1. PONot a statement
    text
    copied!<p>I am learning from a book to code with java. It gives an example of a guessing game and gives the code. I wanted to keep it as a reference. But I keep getting an error. And it might be the way I typed it cause I am reading it off a kindle and it kinda got a little messed up.</p> <p>There are many errors like this, but none like mine. I am trying to make a guessing game, but I keep getting this error:</p> <p>GuessingGame.java:17: not a statement (int)(Math.random() * 10) + 1;</p> <p>Code:</p> <pre><code>import java.util.Scanner; public class GuessingGame { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { bolean keepPlaying = true; System.out.println("Let's play a guessing game!"); while (keepplaying) { bolean validInput; int number, guess; String answer; // Pick a random number = (int)(Math.random() * 10) + 1; // Get the guess System.out.print("What do you think it is? "); do { guess = sc.nextInt(); validInput = true; if ((guess &lt; 1) || (guess &gt; 10)) { System.out.print ("I said between 1 and 10. " + "Try again: "); validInput = false; } }while (!validInput); // Check the guess if (guess == number) System.out.println( "You're right!"); else System.out.println( "You're wrong! " + "The number was " + number); // Play again? do { System.out.println("\nPlay again? (Yes or No)"); answer = sc.next(); validInput = true; if (asnwer.equalsIgnoreCase("Yes")); else if (answer.egualsIgnoreCase("No")- keepPlaying = false); else validInput = false; } while (!validInput); } System.out.println("\nThank you for playing!"); } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload