In this page you see a java program to convert decimal numbers to octal numbers. When you run this program,
This program take decimal number as input from user and converts it to octal number. And show output after compile program on the screen.
Program Code
package com.androidpro.in;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Scanner;
public class Main {
Scanner scan;
int num;
void getVal() {
System.out.println("Decimal to Octal");
scan = new Scanner(System.in);
System.out.println("\nEnter the number :");
num = Integer.parseInt(scan.nextLine());
}
void convert() {
String octal = Integer.toOctalString(num);
System.out.println("Octal Value is : " + octal);
}
}
class MainClass {
public static void main(String args[]) {
Main obj = new Main();
obj.getVal();
obj.convert();
}
}
Output
Decimal to Octal
Enter the number :
56
Octal Value is : 70
Process finished with exit code 0