0

For example the unicode number for 'A' is 65, and the one for 'B' is 98.

Thus a, c, e, g, etc have odd unicode numbers and b, d, f, h, etc have even unicode numbers.

How would I go about checking whether a char is odd or even?

Keep in mind I'm not an advanced programmer.

muzion
  • 1
  • You might find this helpful http://stackoverflow.com/a/2006580/8753 in combination with @dasblinkenlight's solution for determining even or odd. – laz Mar 22 '13 at 00:37

1 Answers1

0

In Java, chars can be treated as ints, according exactly to their ASCII value, and thus no casts or Type conversions are needed, and you can simply mod (%) it by 2, which gives you the remainder of the division per 2, thus if it's even or odd

Cutetare
  • 913
  • 8
  • 24
  • thx, for some reason it didn't work when I tried it in my homework, as it is a bit more complicated then that but now I got it to work! – muzion Mar 22 '13 at 01:33
  • then you probably didn't have a "normal" char, and had it converted to Character (or something similiar) at some point. note: char != Character! – Cutetare Mar 22 '13 at 12:35