by Süleyman Petek
5. May 2016 17:25
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);
}