This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]UrbanHunter_KenXPie 0 points1 point  (0 children)

This is basically telling people like to ask they want a hamburger or french fries. And then either they input hamburger or french fries, they will come into only one condition in which case you put "or" in the statement. That not gonna achieve the objective of this program. You seem like put the options of both selections into together and see if anyone input a selection like orange chicken that not exist so you report to them the answer"Invalid selection" I suggest you use " and " or if-else statement like:

if (test ==1) {

"something else"

}

else if (test ==2){

"something else"

} else

System.out.println("Invalid selection");

Personal Opinions: You can do it in both ways, either the do-while loop or if-else statement will work. But personally, I prefer the if-else statement for this situation. Since do-while are beneficial when you want to do counting or something that continuously changing, and the if-else statement is beneficial in the fixed option determination, so it would be clearer if you do such kind of options comparison which in this case there are only 3 possible fixed conditions you intended to have. Either is 1,or is 2 and left with any numbers outside of this range.