//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");
}
System.out.println("How many sattelites does JUPITER have ??");
C = scan.nextInt();
if (C == 79)
{
System.out.println("Congrats ! You got the Third Question Right :)");
points = points + 1;
}
else if (C != 79)
{
System.out.println("Sorry but your answer is wrong :(");
}
class IfStatement {
public static void main(String[] args) {
int number = 10;
// checks if number is less than 0
if (number < 0) {
System.out.println("The number is negative.");
}
System.out.println("Statement outside if block");
}
}
public class TestIfElse {
public static void main(String[] args) {
int a = 5, b = 6;
if (a > b) {
System.out.println("a is greater");
} else {
System.out.println("b is greater");
}
}
}
// Traditional way
if (20 > 18) {
System.out.println("20 is greater than 18");
}
// "efficient" way
int time = 20;
String result = (time < 18) ? "Good day." : "Good evening.";
System.out.println(result);
class Main {
public static void main(String[] args) {
int number = 10;
// checks if number is greater than 0
if (number > 0) {
System.out.println("The number is positive.");
}
// execute this block
// if number is not greater than 0
else {
System.out.println("The number is not positive.");
}
System.out.println("Statement outside if...else block");
}
}