File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes switch case Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "switch case" Watch "switch case" New topic

switch case

Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 481

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

Joined: Feb 07, 2005
Posts: 2398
A character constant can only contain one character.
marc weber

Joined: Aug 31, 2004
Posts: 11343

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.)

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
kwan Jang

Joined: Sep 24, 2006
Posts: 16
just one character,such char a = 'b'; char n='2'
I agree. Here's the link:
subject: switch case
It's not a secret anymore!