//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");
}
if(a && b) // And operator
if(a || b) // Or operator
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");
}
}
int hi = 30
if (hi < 5) {
System.out.println("ok");
}
else {
System.out.println("no");
}
// 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);
public class Sample {
public static void main(String[] args) {
String names[] = { "Jasmine", "Lyka", "Marbie", "Efren", "Tiny", "Soleen" };
for (int i = 0; i < names.length; i++) {
if (names[i].equals("Efren")) {
System.out.println("We found " + names[i]);
break;
}
}
}
}
if (str != null && !str.isEmpty()) {
doSomethingWith(str.charAt(0));
}
int num = 5;
if (n > 0) {
System.out.println("This is a positive number")
}
if (condition1) {
// codes
}
else if(condition2) {
// codes
}
else if (condition3) {
// codes
}
.
.
else {
// codes
}