Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class EvilNumberSpecimen2016{
- public static void main( String args[] ){
- Scanner sc = new Scanner(System.in);
- System.out.print("INPUT\t\t\t: ");
- int n = sc.nextInt();
- if(n>0){
- //convert to binary using the library function toBinaryString()
- String nBinary = Integer.toBinaryString( n );
- System.out.println( "BINARY EQUIVALENT\t: " + nBinary );
- int oneCount=0;
- for( int i=0; i<nBinary.length(); i++ ){
- if( nBinary.charAt( i ) == '1' ) oneCount++;
- }
- System.out.println( "NO. OF 1's\t\t: " + oneCount );
- System.out.print( "OUTPUT\t\t\t: " );
- if( oneCount % 2 == 0 ){
- System.out.println( "EVIL NUMBER" );
- }else{
- System.out.println( "NOT AN EVIL NUMBER" );
- }
- }else System.out.println( "Invalid Input" );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement