/home/caleb/ASDV-Java/Assignments/Lab10_CalebFontenot/src/lab10_calebfontenot/CharacterClassStringClass.java |
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java
package lab10_calebfontenot;
import java.util.Scanner;
public class CharacterClassStringClass {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String userResponse;
boolean loopToggle = true;
int parseCheck;
while (loopToggle) {
System.out.println("Continue looping?");
System.out.println("Please enter y/n or yes/no: ");
userResponse = input.next();
if (userResponse.toLowerCase().charAt(0) == 'y') {
if (userResponse.length() > 1) {
if (userResponse.toLowerCase().equals("yes")) {
System.out.println("You typed '" + userResponse + '\'');
System.out.println("ok!");
} else {
System.out.println("Invalid input! You entered '" + userResponse + '\'');
}
} else {
System.out.println("You typed '" + userResponse + '\'');
System.out.println("ok!");
}
} else if (userResponse.toLowerCase().charAt(0) == 'n') {
if (userResponse.length() > 1) {
if (userResponse.toLowerCase().equals("no")) {
System.out.println("You typed '" + userResponse + '\'');
loopToggle = false;
} else {
System.out.println("Invalid input! You entered '" + userResponse + '\'');
}
} else {
System.out.println("You typed " + userResponse.charAt(0));
loopToggle = false;
}
} else {
try {
parseCheck = Integer.parseInt(userResponse);
System.out.println("Invalid input! You entered " + parseCheck + ", which is an integer!");
} catch (NumberFormatException ex) {
if (!(userResponse.length() > 1)) {
System.out.println("'" + userResponse + "' is an incorrect character!");
} else {
System.out.println("'" + userResponse + "' is too long!");
}
}
}
}
}
}