File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why am i not getting output

 
Raji Addepalli
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • 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);
}
}
 
Corey McGlone
Ranch Hand
Posts: 3271
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Jason Kretzer
Ranch Hand
Posts: 280
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Rob Ross
Bartender
Posts: 2205
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Arun Mishra
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Try making case5 --> case 5
It works giving output 10.
Arun
 
Raji Addepalli
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic