Sriram
Sriram

Reputation: 10578

Incrementing a unicode character?

I am trying to print some Hindi numbers (Unicode range: 0966 - 096F) in my Java code.
The printing is tied to an index that is being incremented by a for loop. Some sample code:

for(int i = 0; i < 10; i++) {
  System.out.println(/* I need the Hindi numbers from 0-9 printed here (value of i in each iteration but in Hindi));
}  

I tried doing this:

System.out.println("\u0966" + i);

Needless to say, that is not working. My question is:
1. How do I increment a number that is represented in Unicode?

Upvotes: 2

Views: 897

Answers (2)

MrSmith42
MrSmith42

Reputation: 10181

for(int i = 0; i < 10; i++) {
  System.out.println((char)(0x966+i));
}  

Upvotes: 4

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 136162

try

    for (int i = 0; i < 10; i++) {
        System.out.println((char) ('\u0966' + i));
    }

Upvotes: 2

Related Questions