How to print Unicode characters in a specific range?

I am trying to create a program that prints all Unicode \ u6000 characters through \ u7000 (1000 characters). My program prints 50 characters, starts a new line, prints another 50, etc. (There are no problems).

I know how to print Unicode characters, but I'm not sure how to print them in stages (adding 1 each time). Here is my program:

public class UnicodePrinter { public static void main(String args[]) { for (int i = 6000; i<7000; i++) { if(i%50 == 0) { System.out.println(); } System.out.print("\u"+i); //issue here, see below } } } 

I get an error in my print statement, where I typed "\u"+i , saying "Invalid unicode" because \u not filled with numbers, but I have no idea how to fix it.

+5
source share
2 answers

Just generate a char directly, for example:

 public class UnicodePrinter { public static void main(String args[]) { for (char i = '\u6000'; i < '\u7000'; i++) { if (i % 50 == 0) { System.out.println(); } System.out.print(i); //issue here, see below } } } 
+8
source

Just translate it to char after converting it to hex:

 for (int i = 6000; i<7000; i++) { if(i%50 == 0) { System.out.println(); } char c = (char) Integer.parseInt(String.valueOf(i), 16); System.out.print(c); } 
-1
source

All Articles