Advertisement
Guest User

EvilNumSpecimen2016

a guest
Feb 14th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import java.util.*;
  2. class EvilNumberSpecimen2016{
  3. public static void main( String args[] ){
  4. Scanner sc = new Scanner(System.in);
  5. System.out.print("INPUT\t\t\t: ");
  6. int n = sc.nextInt();
  7. if(n>0){
  8. //convert to binary using the library function toBinaryString()
  9. String nBinary = Integer.toBinaryString( n );
  10. System.out.println( "BINARY EQUIVALENT\t: " + nBinary );
  11. int oneCount=0;
  12. for( int i=0; i<nBinary.length(); i++ ){
  13. if( nBinary.charAt( i ) == '1' ) oneCount++;
  14. }
  15. System.out.println( "NO. OF 1's\t\t: " + oneCount );
  16. System.out.print( "OUTPUT\t\t\t: " );
  17. if( oneCount % 2 == 0 ){
  18. System.out.println( "EVIL NUMBER" );
  19. }else{
  20. System.out.println( "NOT AN EVIL NUMBER" );
  21. }
  22. }else System.out.println( "Invalid Input" );
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement