Spotify Labs Puzzles -Easy- Solution with Java

by Süleyman Petek 5. Mayıs 2016 17:25
public static void main(String[] args) {               

public static void main(String[] args) {        

        int yourNumber; 

        Scanner in = new Scanner(System.in);

        System.out.println("Enter your number");

        yourNumber = in.nextInt();        

        

        if (yourNumber < 0) {

            System.out.println("Error: Less then Zero");

        } 

        else 

        { 

            System.out.print("Binary is: ");           

            toBinary(yourNumber);

        }

    }

 

    public static void toBinary(int int1){       

       System.out.println(Integer.toBinaryString(int1));               

       String b = new StringBuffer(Integer.toBinaryString(int1)).reverse().toString();       

       System.out.println("The reverse in binary format is: "+ b);                  

       int decimalValue = Integer.parseInt(b, 2);           

       System.out.println("The reverse decimal is:" +decimalValue); 

   }


For harder ones, please visit https://labs.spotify.com/puzzles/ (:

Tags: , , , , ,

Geyik | Innovation | Tech | Tip

Add comment

Calendar

<<  Mayıs 2018  >>
PztSalÇarPerCumCmtPaz
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

RecentPosts