Conditional and boolean Learn programming Java


Basic Data Types


Conditional and boolean


Create 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.


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.out.print("Enter Second number: ");
		num2 = Integer.parseInt(new Scanner(;

		bothEven = ((num1 % 2 == 0) && (num2 % 2 == 0)) ? true : false;

		System.out.println(bothEven ? "there're numbers bothEven" : "there's a number odd");

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.