java

Java Program to Convert Binary Number to Decimal

In this tutorial, we are going to see how to write a java program to convert binary numbers to decimal numbers using the Integer.parseInt() method. The parseInt() method is used to get the primitive type of a string.
 

Program to Convert Binary Number to Decimal in Java :
import java.util.Scanner;

public class Main {
	
    public static void main(String args[]){
		
       Scanner sc = new Scanner(System.in);
       System.out.print("Enter a binary number: ");
       String b = sc.nextLine();
       System.out.println("The decimal number is: "+Integer.parseInt(b,2));
    }
}

Output:

Enter a binary number: 0101
The decimal number is: 5
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *