// This program converts integers to octals in the java programming language. import java.util.Scanner; public class Octal { public static void main ( String Args[] ) { Scanner input = new Scanner ( System.in ); int decimal, number1, number2, number3, number4, number5, number6; System.out.print (" Please enter a number between 0 and 262143: "); decimal = input.nextInt(); if (decimal < 8) System.out.printf (" Your integer number %d is 00000%d in octal.\n", decimal, decimal); else if (decimal <= 63) { number2 = decimal % 8; number1 = decimal / 8 % 8; System.out.printf (" Your integer number %d is 0000%d%d in octal.\n", decimal, number1, number2); } else if (decimal <= 511) { number3 = decimal % 8; number2 = decimal / 8 % 8; number1 = decimal / 8 / 8 % 8; System.out.printf (" Your integer number %d is 000%d%d%d in octal.\n", decimal, number1, number2, number3); } else if (decimal <= 4095) { number4 = decimal % 8; number3 = decimal / 8 % 8; number2 = decimal / 8 / 8 % 8; number1 = decimal / 8 / 8 / 8 % 8; System.out.printf (" Your integer number %d is 00%d%d%d%d in octal.\n", decimal, number1, number2, number3, number4); } else if (decimal <= 32767) { number5 = decimal % 8; number4 = decimal / 8 % 8; number3 = decimal / 8 / 8 % 8; number2 = decimal / 8 / 8 / 8 % 8; number1 = decimal / 8 / 8 / 8 / 8 % 8; System.out.printf (" Your integer number %d is 0%d%d%d%d%d in octal.\n", decimal, number1, number2, number3, number4, number5); } else if (decimal <= 262143) { number6 = decimal % 8; number5 = decimal / 8 % 8; number4 = decimal / 8 / 8 % 8; number3 = decimal / 8 / 8 / 8 % 8; number2 = decimal / 8 / 8 / 8 / 8 % 8; number1 = decimal / 8 / 8 / 8 / 8 / 8 % 8; System.out.printf (" Your integer number %d is %d%d%d%d%d%d in octal.\n", decimal, number1, number2, number3, number4, number5, number6); } else if (decimal > 262143) System.out.print ("UNABLE TO CONVERT\n"); } }