Answers for ""java" even or odd without conditional statements"

0

"java" even or odd without conditional statements

public class NumberEvenOrOdd {
    public static void main(String []args){
 
        int number = 11;
        String[] results = {"EVEN", "ODD"};
//Every odd number has 1 at the end of its binary representation.
//So AND operation with 1 results in 1
        System.out.println(number + " is " + results[number & 1 ]);



    }//close main

}//close Class
//Credit to YouTube Debabrata Paul
Posted by: Guest on October-12-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language