mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-07 09:45:04 +08:00
Merge pull request #16 from shivhek25/master
Added Decimal to Octal conversion.
This commit is contained in:
19
Decimal to octal.java
Normal file
19
Decimal to octal.java
Normal file
@ -0,0 +1,19 @@
|
||||
#import java.util.*;
|
||||
class Decimal_Octal
|
||||
{
|
||||
public static void main()
|
||||
{
|
||||
Scanner sc=new Scanner(System.in);
|
||||
int n,k,d,s=0,c=0;
|
||||
n=sc.nextInt();
|
||||
k=n;
|
||||
while(k!=0)
|
||||
{
|
||||
d=k%8;
|
||||
s+=d*(int)Math.pow(10,c++);
|
||||
k/=8;
|
||||
}
|
||||
System.out.println("Decimal number:"+n);
|
||||
System.out.println("Octal equivalent:"+s);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user