Skip to content
Advertisement

Save to a variable the number of times the user answered “no” in java

good afternoon, I’m studying java, happened to get an assignment to make the following questions:

  1. give input to the scanner “do you want to close this application? “
  2. If the answer is “no”, the input will appear again with the same question.
  3. If the answer is “yes” the input does not appear again.
  4. Save to a variable the number of times the user answered “no”

I want to make a count when the user answers NO it will count.

JavaScript

Advertisement

Answer

Based on your question, you just need to save the result on ‘the number of times the user answered “no”‘. I suggest you to use while loop and a variable to store the value

JavaScript

but I suggest you to use more user friendly input detection if you getting the input from keyboard typing. Use the equalsIgnoreCase to able to take any other string "TIDAK" format. Here is the example

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement