So, I’ve got two strings being input and the subString looked for in the mString. When I change the method to boolean it returns the correct output of true or false (by using return on the contains statement).
I don’t know how to use that statement to check the outcome of that contains operator. I’ve got the following done up.
public class CheckingString
{
public static void main(String[] args)
{
// adding boolean value to indicate false or true
boolean check;
// scanner set up and input of two Strings (mString and subString)
Scanner scan = new Scanner(System.in);
System.out.println("What is the long string you want to enter? ");
String mString = scan.nextLine();
System.out.println("What is the short string that will be looked for in the long string? ");
String subString = scan.nextLine();
// using the 'contain' operator to move check to false or positive.
// used toLowerCase to remove false negatives
check = mString.toLowerCase().contains(subString.toLowerCase());
// if statement to reveal resutls to user
if (check = true)
{
System.out.println(subString + " is in " + mString);
}
else
{
System.out.println("No, " + subString + " is not in " + mString);
}
}
}
Is there a way to make that check field work properly to return a value in the if-else statement?
should be:
Normally you would write:
to check for true
and:
or:
to check for false.