Radix conversion is an important aspect of programming regardless of the language a developer is using. Java provides a few utility methods that can support these functions and conversions. In today’s quick tip tutorial on Java programming, we’ll show programmers an example of how to convert decimal values to octal values.
The following code shows how to convert decimal values to octal values using Java:
* / public class ConvertToOctal {int decimalNum = 345; int octalRadix = 8; public static void main (String args[]) {ConvertToOctal convertToOctal = new ConvertToOctal (); convertToOctal.proceed (); } continue private void () {String octalNum = Integer.toString (decimalNum, octalRadix); System.out.println (“Octal value of” + DecimalNum + “is” + OktalNum); }} / *
When you run this code in your code editor or integrated development environment (IDE), you get the following output:
[[email protected]]# java ConvertToOctal Octal value of 345 is 531