LotsaHexadecimalFun.java - import java.util.Scanner public...

This preview shows page 1 - 3 out of 3 pages.

import java.util.Scanner;public class LotsaHexadecimalFun {public static void main(String[] args){/*boolean isValid;String hexNum;do{System.out.println("Please enter a valid Hexadecimal: ");hexNum = input.next();isValid = false;for (int i = 0; i < hexNum.length(); i++){System.out.println("Debug: making sure we get every character: " + hexNum.charAt(i)); String possible = "123456789ABCDEF";System.out.println("Result of indexOf: " + possible.indexOf(hexNum.charAt(i)));if (possible.indexOf(hexNum.charAt(i)) == -1){isValid = false;}}}while(!isValid);System.out.print("Debug: got a valid Hexadecimal!");int decOutput = 0;int decChar = hexNum.charAt(0);//decOutput = decChar *(int) Math.pow(16, hexNum.length()-1);//decOutput += decChar *(int) Math.pow(16, hexNum.length()-2);for ( int i = hexNum.length()-1; i >= 0; i--){switch(hexNum.charAt(hexNum.length()-1 -i)){case '0':decChar = 0;break;case '1':decChar = 1;break;case '2':decChar = 2;break;case '3':decChar = 3;break;case '4':decChar = 4;break;case '5':decChar = 5;break;case '6':decChar = 6;break;case '7':decChar = 7;break;case '8':
decChar = 8;break;case '9':decChar = 9;break;case 'A':decChar = 10;break;case 'B':

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture