This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • 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:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

unreachable statement error

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! Sorry about using the wrong format!
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 326
Android Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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... ;)
 
Marshal
Posts: 79973
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79973
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79973
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 5
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???
 
An elephant? An actual elephant. Into the apartment. How is the floor still here. Hold this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic