import.java.util.Scanner;
public class Test{
public static void main(String[] args){
Scanner sc = new Scanner(System.in)
String operation = sc.nextLine();
}
}
When I want to see, if the string operation contains certain letters, I could write f.ex.
if(operation.contains("a") || operation.contains("b")){
System.out.println("This is not a valid choice. Please retry!");
}
But I want to know what to write, if the string contains letters, e.g. from a to k. If I write it with || every single time, it's not efficient. EDIT: I'm only allowed to use the methods contains and equals.
Try using a regex:
An alternative:
A later update
Oh,
indexOf()
is not allowed too. A version which uses nested loops: