Java program to convert decimal number to binary value



The java.lang.Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int.

The toBinaryString() method of the Integer class returns a string representation of the integer argument as an unsigned integer in base

Example

import java.util.Scanner;
public class DecimalToBinary {
   public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter a decimal number ::");
      int decimal = sc.nextInt();

      String result = Integer.toBinaryString(decimal);
      System.out.println("Binary value of the given decimal number is ::"+result);
   }
}

Output

Enter a decimal number ::
444
Binary value of the given decimal number is ::110111100
Lakshmi Srinivas
Lakshmi Srinivas

Programmer / Analyst / Technician


Advertisements