➽ Program:-

import java.util.*;

import java.io.*;

class Main

{

    public static int binary_t_octal(long binary_number)

    {

        int octal_number = 0, decimal_number = 0, i = 0;

        while(binary_number != 0)

        {

            decimal_number += (binary_number % 10) * Math.pow(2,i);

            ++i;

            binary_number/=10;

        }

 

        i = 1;

 

        while(decimal_number != 0)

        {

            octal_number += (decimal_number % 8) * i;

            decimal_number /= 8;

            i *= 10;

        }

 

        return octal_number;

    }

   

    public static void main(String args[])

    {

         long binary_number;

         Scanner sc = new Scanner(System.in);

        

         System.out.print("Enter the Binary Number: ");

         binary_number = sc.nextLong();

        

         int octal = binary_t_octal(binary_number);

        

         System.out.print("Octal Value is "+octal);

    }

}

➽ Output:-

Enter the Binary Number: 11100
Octal Value is 34