Question
Program to convert decimal to octal
ENTER DECIMAL NUMBER:25
THE OCTAL VALUE OF DECIMAL 25 IS 31
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
import java.util.Scanner;
public class DecimalToOctal
{
public static void main()
{
int count=0;
Scanner sc=new Scanner(System.in);
long decimal=0,octal=0,temp=0;
count=0;
System.out.print("ENTER DECIMAL NUMBER:");
decimal=sc.nextInt();
temp=decimal;
count=0;
while(temp>0)
{
octal=octal+(temp%8)*(long)Math.pow(10,count);
count++;
temp=temp/8;
}
System.out.println("THE OCTAL VALUE OF DECIMAL "+decimal+" IS "+octal);
}
}