Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


[Java] Need Help filter_list
Author
Message
[Java] Need Help #1
Hello HC!
Today I have an assignment that I am doing for java, but I need some help. Here is the assignment:



Write a program that asks a user for input. If the user presses enter, the input is echoed back to the command line. The computer asks again for input (and echoes it back) until the user enters "exit" or "quit".

An example output might look like this:

Quote:your input?
aaa
aaa

your input?
Hello
Hello

your input?
exit



I have researched about this...I know that I need to use the scanner utility and use the scanner to set the variable that the user types in and then use a loop to make it keep repeating an if statement or something until it reads the exit. My problem is I don't know what loop to use or anything. I looked up the while, do while, and for loop, but didn't find a way to apply it. I do not want the code just handed to me, I just want to know what to use in order to make this work. Any help would be appreciated. Thank you very much for your time.

Reply

[Java] Need Help #2
Hello HC!
Today I have an assignment that I am doing for java, but I need some help. Here is the assignment:



Write a program that asks a user for input. If the user presses enter, the input is echoed back to the command line. The computer asks again for input (and echoes it back) until the user enters "exit" or "quit".

An example output might look like this:

Quote:your input?
aaa
aaa

your input?
Hello
Hello

your input?
exit



I have researched about this...I know that I need to use the scanner utility and use the scanner to set the variable that the user types in and then use a loop to make it keep repeating an if statement or something until it reads the exit. My problem is I don't know what loop to use or anything. I looked up the while, do while, and for loop, but didn't find a way to apply it. I do not want the code just handed to me, I just want to know what to use in order to make this work. Any help would be appreciated. Thank you very much for your time.

Reply

RE: [Java] Need Help #3
You could do it with any of the loop, but more preferably while or do-while loop. Take the input from the user inside the loop block, check if it is equal to quit. If yes, then break the loop and exit the program. Else just output what was inputted and carry on with the iteration till the required condition is met.
Smile
Folow me on My YouTube Channel if you're into art.

Reply

RE: [Java] Need Help #4
You could do it with any of the loop, but more preferably while or do-while loop. Take the input from the user inside the loop block, check if it is equal to quit. If yes, then break the loop and exit the program. Else just output what was inputted and carry on with the iteration till the required condition is met.
Smile
Folow me on My YouTube Channel if you're into art.

Reply

RE: [Java] Need Help #5
https://github.com/oneluckyducky/RockPap...S.java#L23

This'll explain it all ^-^

Reply

RE: [Java] Need Help #6
https://github.com/oneluckyducky/RockPap...S.java#L23

This'll explain it all ^-^

Reply

RE: [Java] Need Help #7
Algorithm:
Quote:1)Ask the user for input.
2)print out the input.
3)Start the while loop with the condition while user input not equal to exit or out.
3a)Ask the user for input.
3b)print out the input.

Whats while loop?
Quote:its a structure which repeats/loop itself until the condition given to it is true.
[Image: fow57.jpg]

Reply

RE: [Java] Need Help #8
Algorithm:
Quote:1)Ask the user for input.
2)print out the input.
3)Start the while loop with the condition while user input not equal to exit or out.
3a)Ask the user for input.
3b)print out the input.

Whats while loop?
Quote:its a structure which repeats/loop itself until the condition given to it is true.
[Image: fow57.jpg]

Reply

RE: [Java] Need Help #9
Now that I see the question here, I will post, what I wrote LightX in a PM. Maybe others find this useful as well:

A little loop guide:

Use for loops if you have to count or iterate through elements, i.e.
counting from 1 to 10
doing something for all elements in a list

Use a do-while loop if you know that the code within the loop block should be executed at least once, no matter what happens.
i.e.

Code:
do{
   boilWhater()
}while(eggIsNotFinished);

You know that the egg can't be finished unless you started boiling water.

Use a while loop if the code within the block is maybe never executed.
I.e.

Code:
while(sunIsShining) {
   mow();
}

You never even start to mow() if the sun doesn't shine

However, it is not really a problem if you use the "wrong" loop. You can actually use every loop, like you can use every knife for cutting. It is just a matter of readability and convenience to use the right one.

What do you think is the best loop in your case?
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: [Java] Need Help #10
Now that I see the question here, I will post, what I wrote LightX in a PM. Maybe others find this useful as well:

A little loop guide:

Use for loops if you have to count or iterate through elements, i.e.
counting from 1 to 10
doing something for all elements in a list

Use a do-while loop if you know that the code within the loop block should be executed at least once, no matter what happens.
i.e.

Code:
do{
   boilWhater()
}while(eggIsNotFinished);

You know that the egg can't be finished unless you started boiling water.

Use a while loop if the code within the block is maybe never executed.
I.e.

Code:
while(sunIsShining) {
   mow();
}

You never even start to mow() if the sun doesn't shine

However, it is not really a problem if you use the "wrong" loop. You can actually use every loop, like you can use every knife for cutting. It is just a matter of readability and convenience to use the right one.

What do you think is the best loop in your case?
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply







Users browsing this thread: 1 Guest(s)