• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

why am i not getting output

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class test3{
public static void main(String args[])
{
int x,y=10;
switch(y) {
case 10: x=5;
break;
case5 : break;
default: x=0;
}
System.out.println(y);
}
}
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Raji Addepalli:
public class test3{
public static void main(String args[])
{
int x,y=10;
switch(y) {
case 10: x=5;
break;
case5 : break;
default: x=0;
}
System.out.println(y);
}
}


My best guess would be that you need a space after the keyword case and before the number 5. Without the space, the compiler won't recognize that as the keyword case, but as a new identifier for a label. Is this compiling? I'm surprised that you're not getting an "unreachable code" error.
Corey
 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First off, you need to put a space between the word case and the number 5. I did this and it runs fine- outputting 10 like it should.
What problems are you having?
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My first guess is because this code won't compile, at least not on jdk 1.3.0_02.
I think there's a simple typo in your case label:
case5 : break; :roll:

But if you fix this:
case 5 : break;
There is output, so I am confused by your question.
What are you expecting to see?
Rob
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Try making case5 --> case 5
It works giving output 10.
Arun
 
Raji Addepalli
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my mistake is i haven't put space between case and number 5 .I got the output as 10.Thanks a lot
[ January 10, 2002: Message edited by: Raji Addepalli ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic