Source code for UseTheForceExample3.java:

public class UseTheForceExample3
{
	public static void main(String args[])
	{
		// UseTheForceExample3
		String force = "Use the force, Luke!";
		String findString = "Luke";
		int findStringLength = findString.length();
		int startIndex = force.indexOf(findString);
		int endIndex = startIndex + findStringLength;
		String subStr = force.substring(startIndex, endIndex);
		System.out.println("Substring is " + subStr);
	}
}

Output from UseTheForceExample3.java:

Substring is Luke

--- Output Ends ---

NOTE:

You are reading previously generated output. You are not currently running the UseTheForceExample3 application at the momement. You need to compile and run the source code first.

To run this program:


Authors: Kevin Chu and Eric Brower
Copyright 2000 Prentice Hall PTR