java method to convert decimal to binary code example

Example 1: int to binary java

String binary = Integer.toBinaryString(num);

Example 2: Java program to convert decimal to binary using toBinaryString and stack

Convert decimal to binary using toBinaryString() method
public class DecimalToBinary
{
   public static void main(String[] args)
   {
      System.out.println("decimal to binary using toBinaryString() 104: ");
      // to binary string java
      System.out.println(Integer.toBinaryString(104));
      System.out.println("\ndecimal to binary using toBinaryString() 554: ");
      // tobinarystring
      System.out.println(Integer.toBinaryString(554));
      System.out.println("\ndecimal to binary using toBinaryString() 644: ");
      System.out.println(Integer.toBinaryString(644));
   }
}

Tags:

Java Example