- 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
Convert decimal integer to octal in Java
To convert decimal to octal, use the toOctalString() method in Java. Let’s say the following is our decimal.
int decInt = 21;
To convert it to Octal, we need to use the toOctalString() method.
String myOct = Integer.toOctalString(decInt);
The following is the complete example that converts decimal to octal.
Example
public class Demo { public static void main(String []args) { int decInt = 21; System.out.println("Decimal Integer = "+decInt); String myOct = Integer.toOctalString(decInt); System.out.println("Octal = "+myOct); } }
Output
Decimal Integer = 21 Octal = 25
Advertisements