aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why am i not getting output 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 "why am i not getting output" Watch "why am i not getting output" New topic
Author

why am i not getting output

Raji Addepalli
Ranch Hand

Joined: Dec 05, 2001
Posts: 50
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

Joined: Dec 20, 2001
Posts: 3271
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


SCJP Tipline, etc.
Jason Kretzer
Ranch Hand

Joined: May 31, 2001
Posts: 280
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?


Jason R. Kretzer<br />Software Engineer<br />System Administrator<br /><a href="http://alia.iwarp.com" target="_blank" rel="nofollow">http://alia.iwarp.com</a>
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
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


Rob
SCJP 1.4
Arun Mishra
Greenhorn

Joined: Jan 02, 2002
Posts: 16
Hi,
Try making case5 --> case 5
It works giving output 10.
Arun
Raji Addepalli
Ranch Hand

Joined: Dec 05, 2001
Posts: 50
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
 
subject: why am i not getting output
 
Similar Threads
Label for the continue/break statement
head first java - mixed messages
switch statement example
Initializing Sequence
Loop