This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

switch case

 
Shiva Mohan
Ranch Hand
Posts: 484
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Why case �25� is showing error but case �1� and case �4� are not showing error since all are inside the char range? Help please
 
Keith Lynn
Ranch Hand
Posts: 2399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A character constant can only contain one character.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To expand on what Keith said...

Assigned to a char variable, an int literal (without quotes) represents a char value. For example, a decimal value of 51 represents the char '3'.

char three = 51;

But an int inside single quotes is interpreted as a char.

char three = '3';

Similarly, '5' is a char, and '1' is a char. But '51' is not a char.

(And of course, an int inside double quotes is interpreted as a String.)
 
kwan Jang
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just one character,such char a = 'b'; char n='2'
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic