Java Program to Convert Decimal Number to Binary Equivalent Using Integer Wrapper Class Method

Write a Java program to accept number from user and convert it into binary by using wrapper class method..



Source Code
import java.util.Scanner;

public class BinaryUsingWrapper {

	public static void main(String[] args) {

		System.out.print("Enter the number :: ");
		Scanner s = new Scanner(System.in);
		Integer num = s.nextInt();  // Integer wrapper class
		
		// Use toBinaryString( ) Method of Integer wrapper class
		String binaryNumber = Integer.toBinaryString(num); 
		System.out.println("Binary number of " + num + " is :: "+binaryNumber);
	}
}

Output
Enter the number :: 45
Binary number of 45 is :: 101101





"Coding Hub - Learn to code" app now available on Google Play Store