Arronne Montero

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

ALGORITHM

Start

Initialize a Scanner object to read user input.

Enter a do-while loop to repeatedly perform the following steps:

a. Prompt the user to enter a number.

b. Read the user's input as an integer and store it in the 'number' variable.

c. Consume the newline character left in the input buffer.

d. Prompt the user with the question, "Would you like to continue? (Y/N): "

e. Read the user's response as a string and store it in the 'response' variable.

f. Check if the user's response is "Y" or "Yes" (case-insensitive). If true, continue the loop.

g. Check if the user's response is "N" or "No" (case-insensitive). If true, print "Program
terminated" and exit the loop.

h. If neither "Y" nor "N" is entered, display "Invalid Response. Please enter Y or N."

Close the Scanner.

Stop

PSEUDOCODE

Begin

Initialize a Scanner object called 'scanner'

do {

Display "Enter a number: "

Read an integer 'number' from the user

Consume the newline character from the input buffer

Display "Would you like to continue? (Y/N): "

Read a string 'response' from the user

If 'response' is equal to "Y" or "Yes" (case-insensitive):

Continue the loop

Else if 'response' is equal to "N" or "No" (case-insensitive):

Display "Program terminated."


Exit the loop

Else:

Display "Invalid Response. Please enter Y or N."

} while (true)

Close the 'scanner'

End

You might also like