Suppose you are writing a program that asks the user to give a yes-or-no response. Assume that the program reads the user’s response into the String variable response.
a. If response is yes or y, set the boolean variable accept to true otherwise set it to false.
b. How would you change the code so that it will also accept Yes and Y?
a) ```
if( response.equals("y") || response.equals("yes"))
accept = true;
else
accept = false;
```
b) we can add in extra cases:
```
if( response.equals("y") || response.equals("yes") ||
response.equals("Y") || response.equals("Yes"))
accept = true;
else
accept = false;
```
or modify reponse before the if statement.
```
response = response.toLower();
if( response.equals("y") || response.equals("yes"))
accept = true;
else
accept = false;
```
This code is in Fragments.java.
You might also like to view...
Java's ____ is a program that lets you run and view applets without having to run a Web browser.
A. Virtual Machine B. compiler C. debugger D. appletviewer
The current standards for cellular networks today in the United States is 5G.
Answer the following statement true (T) or false (F)