-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecimalToOctal.java
More file actions
31 lines (31 loc) · 910 Bytes
/
DecimalToOctal.java
File metadata and controls
31 lines (31 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Program: Convert Decimal Number to Octal Using Recursion
// Topic: Recursion and Number System Conversion
// Description: Reads a decimal number from user input and recursively converts it to its octal equivalent.
// The method `decToOct()` repeatedly divides the number by
package recursion;
import java.util.*;
/**
*
* @author Samim
*/
public class DecimalToOctal
{
static int tmp=1;
static int oct=0;
public static int decToOct(int num) {
if (num != 0) {
oct = oct + (num % 8) * tmp;
tmp = tmp * 10;
decToOct(num / 8);
}
return oct;
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter Decimal Number");
int num=sc.nextInt();
System.out.println("In Octal :");
System.out.println(decToOct(num));
}
}