The boolean data type is boolean.
Main.java
class Main {
public static void main(String[] args) {
int number = 5;
}
if (isEven(number)) {
System.out.println(number + "Even");
} else {
System.out.println(number + "Odd");
public static boolean isEven(int a) {
return a % 2 == 0;
}
}
In the above, the isEven method checks if the argument value is even and returns true if it is even and false if it is odd.
Recommended Posts