GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Java/Conversions/OctalToDecimal.java at master · loullfly/Java Expand file tree/ Copy pathOctalToDecimal.javaMore file actions 47 lines (43 loc) · 1.09 KB / Copy pathOctalToDecimal.javaFile metadata and controls47 lines (43 loc) · 1.09 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 import java.util.Scanner; /** * Converts any Octal Number to a Decimal Number * * @author Zachary Jones * */ public class OctalToDecimal { /** * Main method * * @param args * Command line arguments */ public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.print("Octal Input: "); String inputOctal = sc.nextLine(); int result = convertOctalToDecimal(inputOctal); if (result != -1) System.out.println("Result convertOctalToDecimal : " + result); sc.close(); } /** * This method converts an octal number to a decimal number. * * @param inputOctal * The octal number * @return The decimal number */ public static int convertOctalToDecimal(String inputOctal) { try { // Actual conversion of Octal to Decimal: Integer outputDecimal = Integer.parseInt(inputOctal, 8); return outputDecimal; } catch (NumberFormatException ne) { // Printing a warning message if the input is not a valid octal // number: System.out.println("Invalid Input, Expecting octal number 0-7"); return -1; } } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |