Java Online Compiler
Example: Decimal to Octal (Built-in) in Java
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// Decimal to Octal (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 a decimal number System.out.print("Enter a decimal number: "); int decimalNumber = scanner.nextInt(); // Step 2: Use Integer.toOctalString() // This method directly converts the decimal integer to its octal string representation. String octalString = Integer.toOctalString(decimalNumber); // Step 3: Display the result System.out.println("Octal equivalent: " + octalString); scanner.close(); } }
Output
Clear
ADVERTISEMENTS