This program converts from hexadecimal to binary. This is my program:
public static void main(String[] args) throws IOException {
int nh = 0, k = 0, j = 0, w = 0, z = 0, lun = 0, r;
String line;
String nb = null;
char nhc = 0;
BufferedReader tastiera = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Inserire il numero in esadecimale");
line = tastiera.readLine();
lun = line.length();
System.out.println(line);
if (lun > 1) {
lun--;
}
for (z = lun; z > 0; z--)
nhc = line.charAt(z);
{
if (nhc == 'a' || nhc == 'A') {
nhc = 10;
}
if (nhc == 'b' || nhc == 'B') {
nhc = 11;
}
if (nhc == 'c' || nhc == 'C') {
nhc = 12;
}
if (nhc == 'd' || nhc == 'D') {
nhc = 13;
}
if (nhc == 'e' || nhc == 'E') {
nhc = 14;
}
if (nhc == 'f' || nhc == 'F') {
nhc = 15;
}
for (k = nhc, w = 0; k > 0 && w < lun * 4; k = k / 2, w++) {
nb.charAt(w) = k % 2;
}
}
System.out.println("Il numero binario è " + nb);
}
This appear when I run:
Inserire il numero in esadecimale
12
12
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - unexpected type required: variable found: value at esadecimale.binario.EsadecimaleBinario.main(EsadecimaleBinario.java:56) Java Result: 1 BUILD SUCCESSFUL (total time: 6 seconds)