Sunday, 20 September 2015

Even Or Odd Number Without (%,/) Operator

package com.tutorial4u;

import java.util.Scanner;

public class EvenOrOdd {
       public static void main(String[] args) {
             System.out.print("Enter a num to check even or odd : ");
             Scanner sc = new Scanner(System.in);
             int num = sc.nextInt();
             if((num&1) == 0){
                    System.out.println("Given number is Even ");
             }else{
                    System.out.println("Given number is Odd");
             }
       }

}

Output: 

Enter a num to check even or odd : 34
Given number is Even 


No comments:

Post a Comment

No of Occurrence in Array

package com.tutorial4u; import java.util.HashMap; /************************************************************  No of Occurrence in Array...