• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unreachable statement error

 
Asha Dore
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch Asha . Please use code tag, while posting your code, next time.
 
Asha Dore
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! Sorry about using the wrong format!
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Jai wrote: . . . Please explain these comments . . .
Do you really need an explanation?
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Manoj Kumar M
Greenhorn
Posts: 5
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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???
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic