JAVA Program Binary to Decimal conversion
Write a JAVA Program
to find the decimal number of binary number.
Description: This java program converts any binary number to its equivalent Decimal number .Save this JAVA program named "BinaryToDecimal.java". If you face any problem please let me know in comment .
Program / Code:
import
java.util.Scanner;
class BinaryToDecimal
{
public static void main (String args [])
{
int bin, dec = 0, k = 1;
Scanner scanner = new Scanner
(System.in);
System.out.println ("Enter the
binary number: ");
bin = scanner.nextInt ();
while (bin != 0)
{
dec = dec + (bin % 10) * k
k * = 2;
bin /= 10;
}
System.out.println ("Decimal
Number = "+dec);
}
}
Output:
No comments:
Your comment will be visible after review.