I am taking a Java course at my local CC, and I have managed to write a fairly concise albeit basic program utilizing a scanner object. The code is attached, and if you think it looks kind of repetitive...well it is. We're supposed to demonstrate a number of techniques. My question is a two-parter. First and foremost, where do you think a good implementation of an if-else structure would be? I was thinking of using one to provide parameters for the user inputed int for the ramCount question (if 1-6 else repeat question with additional print statement specifying the accepted int range). Second, is there anyway to restart the program based on a an if-else question at the end of the program? I have googled it quite a bit, and have seen a solutions using do-while, but I would be interested in completing it using if-else.
Thanks guys, I may be a total noob with code outside of HTML and CSS, but I'm here to learn.
Some contributors here will not follow links to code. Post the relevant code in CODE tags (see my sig).
First and foremost, where do you think a good implementation of an if-else structure would be?
if-else is good wherever you need to choose between two options based on some boolean (true/false) value or expression. Some things you need to decide for yourself.
is there anyway to restart the program based on a an if-else question at the end of the program?
If you want to give the user the choice of restarting the program or quitting, you'll need to put it in a loop so they can loop back to the start. An if-else alone won't do it. Loop structures have a termination condition, which can stop the loop, so they effectively have an if-else built in (e.g. the 'while' condition in a do-while).
If you understand what you're doing, you're not learning anything...
Anon.
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.