String str = "9,10,11,12";
String isIn = " ";
do {
isIn = JOptionPane.showInputDialog("Please enter a number");
if(isIn == null) break;
int x = str.indexOf(isIn);
boolean confirmed = false;
if(x != -1) {
boolean hasLeadingComma = x > 0 && str.charAt(x-1) == ',';
boolean hasTrailingComma = x < str.lastIndexOf(",") &&
str.charAt(x + isIn.length()) == ',';
boolean isFirst = x == 0 && hasTrailingComma;
boolean isLast = x > str.lastIndexOf(",") && hasLeadingComma;
confirmed = isFirst || isLast ||
(hasLeadingComma && hasTrailingComma);
}
if(confirmed) {
System.out.println("Found " + isIn + " at index " + x);
} else {
System.out.println(isIn + " not found, x = " + x);
}
} while(isIn.length() > 0);