Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
32 views4 pages

Program 5 Base N To Decimal

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views4 pages

Program 5 Base N To Decimal

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Program 5 : BASE N TO

DECIMAL
_____________________________________________
import java.util.Scanner;

public class BaseNToDecimal {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number in base n: ");
String number = sc.nextLine();
System.out.print("Enter the base: ");
int base = sc.nextInt();

int decimal = Integer.parseInt(number, base);


System.out.println("Decimal value: " + decimal);
}
}
ALGORITHM
_____________________________________________

Step 1: Start the program and prompt the user to enter a decimal
number.

Step 2: Store the user input in the variable decimal.

Step 3: Prompt the user to enter the base (e.g., 2 for binary, 8 for
octal, 16 for hexadecimal, etc.).

Step 4: Store the user input in the variable base.

Step 5: Convert the decimal number to the specified base using


the method Integer.toString(decimal, base).

Step 6: Store the converted value in the variable result.

Step 7: Display the value of result to the user, indicating the


number in the specified base.
OUTPUT
_____________________________________________
Variable Table
_____________________________________________

You might also like