We received an exercise at college about unicode and ASCII and chars and so on. One part of the exercise is to find a way to read the users input in console that have to be a char and give back the ASCII and Unicode.
Quite easy I think, but my scanner won't scan. Because there's no .nextChar
method for the scanner. I was used to use the String method (scanner.nextLine
). In the next step, I turned the singlechar-String to a char with char ... = s.charAt
and from there I wanted to get the hex and ASCII. Whatever I do my Scanner wont scan the String. Here's the code:
do{
System.out.println("Geben Sie ein Zeichen ein um den dazugehoerigen ASCII- und Unicode anzuzeigen");
input = scan.nextLine();
} while(input.length() >= 2 & input.length() < 1);
zeichen = input.charAt(0);
i = (int) zeichen;
System.out.println("Sie haben " + zeichen + " gewählt.\nDer dazugehoerige ASCII-Code ist " + i + "\nDer dazugehoerige Unicode ist " + (buffer.toString()+ Integer.toHexString(i)));