This Program is suppose to print any strings that contain "ch" in the user entered array. However .... my program does quite the opposite, it only prints strings that do not contain "ch". What can I do to change this? I'm sure the program is here, if (s[x].indexOf("CH") == -1). However, when I try different values it does not print anything.
CODE
import java.util.*;
public class CH {
public static Scanner in = new Scanner (System.in);
public static void main (String[] args) {
String[] x = GetArray ();
Remove (x);
}
public static String[] GetArray() {
int sz = -1;
while (sz<=0)
{System.out.print ("How many strings do you want in the array? ");
sz = in.nextInt();}
in.nextLine();
String[] array = new String [sz];
for (int i = 0; i < sz; i++) {
System.out.print ("Enter string "+(i+1)+": ");
array[i] = in.nextLine();
}
return array;
}
public static void Remove (String[] s) {
for (int x = s.length -1; x >=0; x--) {
if (s[x].indexOf("CH") == -1)
if (s[x].indexOf("Ch") == -1)
if (s[x].indexOf("cH") == -1)
if (s[x].indexOf("ch") == -1)
{System.out.println (s[x]);}
}
}
}