Octal to decimal conversion

Description:

Java program to convert from octal to decimal number Test Case 1 Input (stdin) 10 Expected Output 8 Test Case 2 Input (stdin) 12 Expected Output 10

Program :


import java.util.Scanner;

public class TestClass {

 

public static void main(String[] args)

   {

     Scanner in = new Scanner(System.in);

     long octal_num, decimal_num = 0;

     int i = 0;

     

    octal_num = in.nextLong();

    while (octal_num != 0)

     {

      decimal_num = (long)(decimal_num + (octal_num % 10) * Math.pow(8, i++));

      octal_num = octal_num / 10;

     }

    System.out.print(decimal_num);

   }

}