Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Simple Conditions
- */
- import java.util.Scanner;
- public class _03c_EvenOrOdd
- {
- public static void main(String[] args)
- {
- Scanner scan = new Scanner(System.in);
- int num = Integer.parseInt(scan.nextLine());
- /*
- * Using binary expression and ternary operator (?:) to print the result.
- * If 1st bit of a number is '0', then the number is even, else it's odd.
- * result = Condition ? Statement1 : Statement2;
- */
- System.out.println((num & 1) == 0 ? "Even" : "Odd");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment