Number system program code to convert of Decimal numbers to Octal numbers in Java

Dec2Oct
{
public static void main(String args[])
{
int decN=2520, octN=0, i=1, j, tmp;
tmp=j=decN;
while(j>0)
{
octN=octN+(decN%8)*i;
decN/=8;
j/=8;
i*=10;
}
System.out.println("Decimal Number is: "+tmp);
System.out.println("Octal   Number is:   "+octN);
}
}




No comments

Post your comments

Powered by Blogger.