import java.util.*;
import java.lang.*;
import java.io.*;
class Ideone
{
{
ResultOfIndexOf result = StringUtil.indexOf("hello, world", 'l');
if (result.isFound())
System.
out.
println(String.
format("index=%d", result.
foundIndex())); }
}
class StringUtil {
public static ResultOfIndexOf indexOf
(String haystack,
char needle
) { for (int i = 0; i < haystack.length(); ++i)
if (haystack.charAt(i) == needle)
return new ResultOfIndexOf(i);
return new ResultOfIndexOf();
}
}
class ResultOfIndexOf {
private final boolean isFound;
private final int foundIndex;
ResultOfIndexOf() {
this(false, 0);
}
ResultOfIndexOf(int foundIndex) {
this(true, foundIndex);
}
private ResultOfIndexOf(boolean isFound, int foundIndex) {
this.isFound = isFound;
this.foundIndex = foundIndex;
}
public boolean isFound() {
return isFound;
}
public int foundIndex() {
if (!isFound)
return foundIndex;
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpjbGFzcyBJZGVvbmUKewoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBqYXZhLmxhbmcuRXhjZXB0aW9uCgl7CgkJUmVzdWx0T2ZJbmRleE9mIHJlc3VsdCA9IFN0cmluZ1V0aWwuaW5kZXhPZigiaGVsbG8sIHdvcmxkIiwgJ2wnKTsKCQlpZiAocmVzdWx0LmlzRm91bmQoKSkKCQkJU3lzdGVtLm91dC5wcmludGxuKFN0cmluZy5mb3JtYXQoImluZGV4PSVkIiwgcmVzdWx0LmZvdW5kSW5kZXgoKSkpOwoJfQp9CgpjbGFzcyBTdHJpbmdVdGlsIHsKCXB1YmxpYyBzdGF0aWMgUmVzdWx0T2ZJbmRleE9mIGluZGV4T2YoU3RyaW5nIGhheXN0YWNrLCBjaGFyIG5lZWRsZSkgewoJCWZvciAoaW50IGkgPSAwOyBpIDwgaGF5c3RhY2subGVuZ3RoKCk7ICsraSkKCQkJaWYgKGhheXN0YWNrLmNoYXJBdChpKSA9PSBu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