Hello, so I have to create a program in java that does not use any automatic converting libraries. I've completed decimal to binary, and now im stuck on decimal to hexadecimal. The code i've wrote for this is below. Any comments would be greatly appreciated.
public void getDec() { String Dec; Dec = JOptionPane.showInputDialog("Please enter the decimal number you would like to convert"); num = Integer.parseInt(Dec); } public void decToHex() { getDec(); //ask user for a decimal int hex[] = new int[8]; //container for new hexadecimal int i, j = 0; while (num != 0) //base 16 code { num = num / 16; hex[i]=num; hex[i] = hex[i] % 16; i++; } while(hex[j]>=10) { switch(hex[j]) { case 10: hex[j] = 'A'; j--; break; case 11: hex[j] = 'B'; j--; break; case 12: hex[j] = 'C'; j--; break; case 13: hex[j] = 'D'; j--; break; case 14: hex[j] = 'E'; j--; break; case 15: hex[j] = 'F'; j--; break; } } //System.out.println(?); }