-2
I am unable to make this program repeat after the user has put an invalid answer.
If he/she type a response does not validate how it could be done for the program to run again to be put the response as requested?
import java.util.Scanner;
public class InputValidationString {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in= new Scanner(System.in);
System.out.println(" Do you like to code?:");
String liketocode=in.nextLine();
if (liketocode.equalsIgnoreCase("Y")) {
System.out.println("That's great! I do too!");
} if (liketocode.equalsIgnoreCase("N")) {
System.out.println("That's ok. There are many other wonderful things in life to learn.");
} else { System.out.println("Invalid Response! Please answer with a 'Y' or 'N'.");
} while (liketocode.equalsIgnoreCase("Y")||(liketocode.equalsIgnoreCase("N")));
in.close();
// Author : Messias Kennedy
} // the end of main
} // the end of public class