aspose file tools*
The moose likes Beginning Java and the fly likes unreachable statement error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "unreachable statement error" Watch "unreachable statement error" New topic
Author

unreachable statement error

Asha Dore
Greenhorn

Joined: Jul 13, 2011
Posts: 10
Can't figure out why I'm getting unreachable statement errors on my System.out.println lines. Anyone have any ideas?

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

you end thread execution by using return, so the thread execution cant reach System.out.println, hence you are getting the expected exception.

use System.out.println, just before the return statement.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Welcome to JavaRanch Asha . Please use code tag, while posting your code, next time.
Asha Dore
Greenhorn

Joined: Jul 13, 2011
Posts: 10
Thanks! Sorry about using the wrong format!
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11314
    
  16

I added the tags for you - see how much more readable it is now?

I think even if you revers your return and print statements, you still have a problem. Can you tell me what conditions you will ever reach line 20?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

fred rosenberger wrote:Can you tell me what conditions you will ever reach line 20?


That is possible when you use the "Project leader calendar". Then you can be done about 100 years before you start... ;)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38873
    
  23
Nice one! But you need to be done 300 years before you start in this case.

Actually, that is one error the compiler probably cannot catch.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
fred rosenberger wrote:
Can you tell me what conditions you will ever reach line 20?
That is possible when you use the "Project leader calendar". Then you can be done about 100 years before you start... ;)


Nice one! But you need to be done 300 years before you start in this case. Actually, that is one error the compiler probably cannot catch.


Please explain these comments not able to decipher them
Asha Dore
Greenhorn

Joined: Jul 13, 2011
Posts: 10
Got the format right I think.

I changed it quite a bit after further reading. The program compiles and the tester runs. Everything works at this point except the output for a leap year is still saying that it's not a leap year. I'm thinking my arithmetic is way off. Or some other major issue that I'm missing






}


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38873
    
  23
John Jai wrote: . . . Please explain these comments . . .
Do you really need an explanation?
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Check the leap year condition - i am not confident though (not thoroughly tested )

Do you really need an explanation?
Yes
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11314
    
  16

the original code had (boiled down)


So, no matter what the original condition was, we would return from the method in either the 'if' or the 'else' block. There was no way to ever get past it without returning, so the 'line 20' is unreachable.

I think the other comments were jokes about Project Managers setting unrealistic completion dates

Asha Dore
Greenhorn

Joined: Jul 13, 2011
Posts: 10
John Jai wrote:Check the leap year condition - i am not confident though (not thoroughly tested )

Do you really need an explanation?
Yes


Thank you SO much. That totally works. And will help me with my arithmetic in the future.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38873
    
  23
John Jai wrote: . . .
Do you really need an explanation?
Yes
You can't explain a joke.

And try (i & 3) == 0 instead of i % 4 == 0. I'll let you work out why, but it will give slightly faster execution.
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

Campbell Ritchie wrote:
And try (i & 3) == 0 instead of i % 4 == 0. I'll let you work out why, but it will give slightly faster execution.


That was a nice one.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Campbell Ritchie wrote:And try (i & 3) == 0 instead of i % 4 == 0. I'll let you work out why, but it will give slightly faster execution.

I tried changing the code like below & saw execution time in milli seconds. I did not see any difference. Correct the code if its wrong

I used inputs 1992, 1994 & 1996 so that every time the third condition got hit and looped for 1000 times in for loop
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

This kind of optimization is micro optimization, as the difference will hardly ever exceed microseconds, perhaps not even nanoseconds. I'd never use "& 3" because "% 4" is simply easier to understand.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Manoj Kumar M
Greenhorn

Joined: Jul 16, 2011
Posts: 5


dear all
i too used bitwise code found in web to optimise the performance in some areas. Can any one tell me some good technical resource to learn java bitwise operators???
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unreachable statement error