- 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
Java program to convert float decimal to Octal number
We can convert any decimal number to its equivalent octal by following program.
In this we reserve the reminder we get after divide the given number by 8 as it is the base of Octal and then reverse the order of reminders we have stored by multiplying each reminder by 10.Let understand by following example.
Example
public class DecimalToOctal { public static void main(String[] args) { int decimal = 84; int octalNumber = 0, i = 1; while (decimal != 0) { octalNumber += (decimal % 8) * i; decimal /= 8; i *= 10; } System.out.println("Octal of given decimal is " + octalNumber); } }
Output
Octal of given decimal is 124
Advertisements