Wednesday, August 5, 2020

Write a program to input a number in Octal form and convert it Decimal form? (10 in octal then 8 in decimal, 8^0, 8^1, ….)

74)  Write a program to input a number in Octal form and convert it Decimal form? (10 in octal then 8 in decimal, 80, 81, ….)


import java.util.*;
public class Octal_to_Decimal
{
    public static void main(String args[ ])
  {
           Scanner sc = new Scanner (System.in);
           System.out.println("Enter a OCTAL number");
           int b = sc.nextInt();
           int a = b;
           int m = 0;
           int r = 0;
           while(a>0)
           {
               int d = a%10;
               int x = (int)Math.pow(8,m);
               r = r+(x*d);
               m++;
               a=a/10;
           }
           System.out.println(b+" in DECIMAL = "+r);
  }
}

Output :


 
 


No comments:

Post a Comment

if you have any doubts, Please let me know.
Your Truly
Shashank Porwal

 jhvghvgk ;nkjn ,nkjhj