- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Parse and format a number to octal in Java
To parse and format a number to octal, try the following code −
Example
public class Demo { public static void main( String args[] ) { int val = Integer.parseInt("150", 8); System.out.println(val); String str = Integer.toString(val, 8); System.out.println(str); } }
Output
104 150
In the above program, we have used the Integer.parseInt() and Integer.toString() method to convert a number to octal.
int val = Integer.parseInt("150", 8); String str = Integer.toString(val, 8);
The toString() method above represents a value in string and formats.
We have set the radix as 8, since octal is represented by radix 8.
- Related Articles
- Parse and format a number to decimal in Java
- Java Program to Parse and Format a Number into Binary
- Parse and format to hexadecimal in Java
- Parse Octal string to create BigInteger in Java
- Format and Parse Date in Java
- Java Program to parse Time using custom format
- Parse and format to arbitrary radix
- Convert octal number to decimal number in Java
- Java Program to parse string date value with default format
- Java Program to convert octal number to decimal number
- Java program to convert decimal number to octal value
- Java program to convert float decimal to Octal number
- Java Program to convert decimal integer to octal number
- Precision on a number format in Java
- Format floating point number in Java

Advertisements