**Question:**

Write a Program in Java to input a number in Decimal number system and convert it into its equivalent number in the Octal number system.

**Note:** Octal Number system is a number system which can represent a number in any other number system in terms of digits ranging from 0 to 7 only. This number system consists of only eight basic digits i.e. 0, 1, 2, 3, 4, 5, 6 and 7.

For Example: 25 in the Decimal number system can be represented as 31 in the Octal number system.

**Solution:**

/** * The class Dec2Oct inputs a Decimal number and converts it into its equivalent Octal number * @author : www.javaforschool.com * @Program Type : BlueJ Program - Java */ import java.io.*; class Dec2Oct { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader (new InputStreamReader(System.in)); System.out.print("Enter a decimal number : "); int n=Integer.parseInt(br.readLine()); int r; String s=""; //variable for storing the result //array storing the digits (as characters) in the octal number system char dig[]={'0','1','2','3','4','5','6','7'}; while(n>0) { r=n%8; //finding remainder by dividing the number by 8 s=dig[r]+s; //adding the remainder to the result and reversing at the same time n=n/8; } System.out.println("Output = "+s); } }

**Output:**

Enter a decimal number : 25

Output = 31

Enter a decimal number : 465

Output = 721

**Note:**Don’t forget to share these resources and links from our website in your social networking sites with your friends and followers.]

Thank you so much!!!

i find this site awesome

how to do the above program using recursion…..???? please reply …URGENT…

Hello Arka, Here you go:

I think you will find this useful: http://www.guideforschool.com/372-collection-of-number-based-programs-using-recursion-isc-computer-science/

and http://www.guideforschool.com/345-collection-of-string-programs-using-recursion-isc-computer-science/

Regards,

guideforschool

Great Resources! Easy codes! Perfect for shorthand preparation! Logic applied is very free – flowing too! GREAT WORK #GUIDE_FOR_SCHOOL TEAM! 🙂