borkins

03c. Even or Odd

Mar 23rd, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. /*
  2.  * Simple Conditions
  3.  */
  4. import java.util.Scanner;
  5.  
  6. public class _03c_EvenOrOdd
  7. {
  8.     public static void main(String[] args)
  9.     {
  10.         Scanner scan = new Scanner(System.in);
  11.  
  12.         int num = Integer.parseInt(scan.nextLine());
  13.        
  14.         /*
  15.          * Using binary expression and ternary operator (?:) to print the result.
  16.          * If 1st bit of a number is '0', then the number is even, else it's odd.
  17.          * result = Condition ? Statement1 : Statement2;
  18.          */
  19.  
  20.         System.out.println((num & 1) == 0 ? "Even" : "Odd");
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment