Write a Java program to convert a octal number to a decimal numberInput Data:Input any octal number: 10Expected Output:
Equivalent decimal number: 8
import java.util.Scanner; public class Exercise25 { public static void main(String[] args) { Scanner in = new Scanner(System.in); long octal_num, decimal_num = 0; int i = 0; System.out.print("Input any octal number: "); 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("Equivalent decimal number: " + decimal_num+"\n"); } }
Sample Output:
Input any octal number: 10 Equivalent decimal number: 8
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output: