Wednesday, February 15, 2012

Tutorial: Decimal to Octal Coverter in Java

Hi guys. It's nice to here again. Today, I will show you a Number System converter program where you can  convert a DECIMAL value to its equivalent OCTAL value. 

In designing this Java program, I follow the rules in converting decimal value to octal. Here is the sample output of the program.



In the figure above, the user must input first a DECIMAL (e.g 170)  number to be converted. Then, by pressing the Enter key from the keyboard, then the program automatically get or compute its equivalent OCTAL value (e.g. 252). I made the algorithm of converting the value following or applying the rules in said conversion. In addition to that, the program also asked the user if she/he wants to continue converting. Now by pressing big or small letter (Y/y), then the user will be able to the conversion again, else if the user press any key from the keyboard, then definitely the program will be terminated (see the sample output below).

Here is the sample program source code or algorithm that converts the decimal value to octal:

           do
            {
                quotient = dividend/BASE;
                int remainder = (dividend - (quotient*BASE));
                dividend = quotient;
                octal[x] = remainder;
                ++x;
            }while(dividend!=0);

Like Us on Facebook

Related Posts Plugin for WordPress, Blogger...