Java Online Compiler
Example: Octal to Decimal (Built-in) in Java
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// Octal to Decimal (Built-in) import java.util.Scanner; // Main class containing the entry point of the program public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Step 1: Prompt user for an octal number as a string System.out.print("Enter an octal number: "); String octalString = scanner.next(); // Step 2: Use Integer.parseInt() with radix 8 // The second argument '8' specifies that the input string is an octal number. int decimalNumber = Integer.parseInt(octalString, 8); // Step 3: Display the result System.out.println("Decimal equivalent: " + decimalNumber); scanner.close(); } }
Output
Clear
ADVERTISEMENTS