SHOW:
|
|
- or go back to the newest paste.
1 | import java.nio.charset.Charset; | |
2 | import java.nio.charset.StandardCharsets; | |
3 | import java.util.Scanner; | |
4 | ||
5 | public class SomeClass { | |
6 | - | try (Scanner scanner = new Scanner(System.in)) { |
6 | + | |
7 | - | System.out.println("enter a character and hit <enter> to know its Unicode code point"); |
7 | + | |
8 | ||
9 | - | int i = str.codePointAt(0); |
9 | + | Charset charset = Charset.defaultCharset(); |
10 | - | System.out.print(str); |
10 | + | System.out.print("Used charset: "); |
11 | - | System.out.print(": "); |
11 | + | System.out.println(charset); |
12 | - | System.out.println(i); |
12 | + | if (!charset.contains(StandardCharsets.UTF_8)) |
13 | System.out.println("Warning: It does not contain all unicode characters!"); | |
14 | ||
15 | try (Scanner scanner = new Scanner(System.in, charset)) { | |
16 | System.out.println("enter some characters and hit <enter> to know their Unicode code points"); | |
17 | String str = scanner.nextLine(); | |
18 | str.codePoints().forEach(cp -> { | |
19 | System.out.print(new String(Character.toChars(cp))); | |
20 | System.out.print(": "); | |
21 | System.out.println(cp); | |
22 | }); | |
23 | } | |
24 | } | |
25 | } |