Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

having trouble again with certain erros message

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok i cannot do an array in my program! so is there any other way i can return more that one string in my if's statements. Also, i keep getting the following error message againg with each if statement (unreachable statement) i made the if statement print out the word then return it and it still is giving this error. so i dont know what to do
 
Bartender
Posts: 1843
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Part of the problem seems to be formatting. Take a look at this code (better formatted), and the "unreachable statement" error becomesw clearer:

In line A you create an "if"
In line B you return.
In line C you create an else for your if.
IN line D you return within the else.
At this point, you have either returned at line B or you have returned at line D. Anything Line E and beyond is "unreachable"; there is no logical way to get to this code.
Why are you asking about returning multiple values? This code does not seem to reflect that need. Arrays are, of course, the easiest way to do that, but if your professor does not want you to return arrays, you might consider using output parameters. Unfortunately, the easiest way to implement output parameters in Java is with an array....although you could use a List.
 
My, my, aren't you a big fella. Here, have a tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic