Dec 23, 2010

Decimal to Binary in Java

Code:
import java.lang.*;
import java.io.*;
public class DecimalToBinary{
  public static void main(String args[]) throws IOException{
  BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  System.out.println("Enter the decimal value:");
  String decimal= bf.readLine();
  int i = Integer.parseInt(decimal);  
  String binary = Integer.toBinaryString(i);
  System.out.println("Binary: " binary );
  }
}  


Output:


Enter the decimal value: 15
Binary: 1111

No comments:

Post a Comment

Post a Comment

Note: Only a member of this blog may post a comment.