Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

if statement java

//Checks if the guess matches the random number
                if (g1 == Random) {

                    //System print line statement to tell the user that their guess was the same as the random number
                    System.out.println("Correct");

                    //System print line statement to display number of guesses and the word 'guesses'
                    System.out.println(counter + " Guesses");
                }
                //If the guess is lower than the random number the console will print 'Wrong, try higher'
                else if (Random > g1) {
                    System.out.println("Wrong, try higher");
                }
                //If the guess higher than the random number the console will display 'Wrong, try lower'
                else {
                    System.out.println("Wrong, try lower");
                }
 
PREVIOUS NEXT
Tagged: #statement #java
ADD COMMENT
Topic
Name
2+6 =