Java programming project Allow the user to type in a integer
Java programming project. Allow the user to type in a integer or floating point decimal number. Then, you will calculate and display the binary equivalent. Use 2’s complement for negative numbers
Solution
import java.util.*;
class DecimalBinary{
public static void main(String a[]){
System.out.println(\"Enter number: \");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
System.out.println(\"Binary representation is \");
System.out.println(Integer.toBinaryString(n));
}
}
===========================
akshay@akshay-Inspiron-3537:~$ java DecimalBinary
Enter number:
-23
Binary representation is
11111111111111111111111111101001
