// This program converts octal numbers to decimal numbers. import java.util.Scanner; public class Decimal { public static void main ( String args[] ) { int foo; Scanner sc = new Scanner ( System.in ); do { System.out.print ("Enter up to an 8-digit octal number and I'll convert it: "); foo = sc.nextInt(); } while (foo < 0 || foo > 99999999); System.out.printf ( "%d:%d\n", foo, convert(foo)); } /** * This method converts an octal number to a decimal number * * @param octal the octal number to be converted to decimal * @return decimal the octal number converted to decimal */ public static int convert ( int octal ) { int temp, decimal, num1, num2; num1 = 10000000; num2 = 2097152; decimal = 0; while ( num1 > 0 ) { temp = ((octal / num1)% 10)* num2; num1 /= 10; num2 /= 8; decimal += temp; } return decimal; } }