Here we will see a java programs to convart binary numbers to octal numbers. This program take a input by user and show output after compile program.
Code
import java.io.*;
class BinaryToOctal
{
public static void main(String[] args) throws Exception
{
String num = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("\n\nEnter Binary Number : ");
num = br.readLine();
int dec = Integer.parseInt(num, 2);
String oct = Integer.toOctalString(dec);
System.out.println("Binary \t" + num + " \nAfter Convert In Octal " + oct);
}
}
Output
Enter Binary Number : 11 Binary 11 After Convert In Octal 3

0 Comments