Exercise
Conditional and boolean
Objetive
Write a java program that uses the conditional operator to give a boolean variable named "bothEven" the value "true" if two numbers entered by the user are the even, or "false" if any of them is odd.
Example Code
import java.util.*;
public class Main
{
public static void main(String[] args)
{
int num1, num2;
boolean bothEven;
System.out.print("Enter First number: ");
num1 = Integer.parseInt(new Scanner(System.in).nextLine());
System.out.print("Enter Second number: ");
num2 = Integer.parseInt(new Scanner(System.in).nextLine());
bothEven = ((num1 % 2 == 0) && (num2 % 2 == 0)) ? true : false;
System.out.println(bothEven ? "there're numbers bothEven" : "there's a number odd");
}
}