Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BinaryToDecimal {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.print("Enter a binary number: ");
- int binaryNum = scan.nextInt();
- int degree = 0;
- int decimalNum = 0;
- while (binaryNum != 0){
- int number = binaryNum % 10;
- decimalNum = (int) (decimalNum + number * Math.pow(2, degree));
- binaryNum = binaryNum / 10;
- degree = degree + 1;
- }
- System.out.println(String.format("Updated number in decimal number system: %d", decimalNum));
- }
- }
RAW Paste Data