import java.util.*;
import java.lang.*;
import java.io.*;

class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		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)
			throw new RuntimeException("index not found");
		return foundIndex;
	}
}
