How do you write an input validation loop that compares strings? My attempt at the code is included.
Thank You,
Hank
Question 4.6. Write an input validation loop that asks the user to enter “Yes” or “No”.
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
import java.util.Scanner;
/**
CIS-151,
Input Validation Loop
*/
public class Checkpoint4_6 // Name the file.
{
public static void main(String[] args)
{
DecimalFormat formatter = new DecimalFormat("#0.00"); // Create decimal format object.
int number; // number
String input; // hold user input
char ch; //
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter 'Yes' 'No'.");
input = keyboard.nextLine();
//ch = input.charAt(0);
while (input.equals("Yes"))// && (input.equals("No"))
{
System.out.println("Enter 'y', 'Y', 'n' or 'N'.");
input = keyboard.nextLine();
//ch = input.charAt(0);
//System.out.println(input);
}
System.exit(0);
}
}