Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interesting code

 
vidya sagar
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class interest
{
public static void main(String as[])
{
byte b=1;
switch(b)
{
case 5:
System.out.println("Hai I am FIVE");
case 10:
System.out.println("Hai I am TEN");
Default:
System.out.println("Hai I am DEFAULT");
}
}
}

Guys this is one of intersting code i went thru, when i simply work thru

Try it............if not i will be with u for answer
 
Raghu Shree
Ranch Hand
Posts: 143
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vidya,
Default is treat as label. But switch case matches default Label.
So nothing prints here. Am I correct?
cheers!!!

[ April 09, 2005: Message edited by: Raghu Shree ]
 
Ram Naresh
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vidya,
I think java takes 'Default' as a label rather than a keyword 'default'. So try using 'default' instead of Default.
Ram
 
Animesh Shrivastava
Ranch Hand
Posts: 298
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shouldn't it give a compilation error. Default is not a legal case label.
 
vidya sagar
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That the answer i expect from U all Guys
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi vidya
i tried using the different type other thant the int.
i can't able to use the double in the switch case.
is the int is the only type used in the switch or any other type we can use.
 
v nithya
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we can use int,short,char,byte(within the range) in the switch statement.
regards,
nithya
 
sethu chiyan
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Nithya U r xactly right,

Vidya, The answer is nothing, because it takes Default simply as label not as default.

with regards,
Chiyan
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic