Tuesday , 10 December 2019
Latest Posts
Home » ICSE Important Programs » Program on Decimal to Octal Number Conversion

# Program on Decimal to Octal Number Conversion

#### 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
{
System.out.print("Enter a decimal number : ");

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.]

## [Question 2] ISC 2017 Computer Practical Paper Solved – Quiz Result

Solution of Program 2 of ISC 2017 Computer Science Paper 2 (Practical) Exam. Java program to input the answers of each participant row-wise and calculate their marks

1. Thank you so much!!!

2. i find this site awesome

3. • Hello Arka, Here you go:

```import java.io.*;
class Octal_Recursion
{
int oct=0;
int octal(int n)
{
if(n>0)
{
int d=n%8;
octal(n/8);
oct=oct*10+d;
}
return oct;
}

public static void main(String args[])throws IOException
{
Octal_Recursion ob=new Octal_Recursion();
System.out.print("Enter any number : ");
• 