//------------// Introduction to Programming Using Java: An Object-Oriented Approach//	Arnow/Weiss//------------// the isPrefix method// Chapter 10, Section 10.11, Page 427// MODIFICATIONS://    the loop is wrapped in a static method, isPrefix, so//    that it can be tested by a main methodimport java.io.*;class TestisPrefix {	static boolean isPrefix(String s1, String s2) {		//////////////////////////////////////////////////////////////////		int k;	// Position k is the next one to check; the Strings match in all 			//      positions before k.		k  =  0;		while  (k!=s1.length()  &&  k!=s2.length()  &&  s1.charAt(k)==s2.charAt(k))			k++;		boolean  s1IsAPrefix  =  k==s1.length();		//////////////////////////////////////////////////////////////////		return s1IsAPrefix;	}	static boolean testisPrefix(String s1, String s2, boolean isprefix) {		if (isprefix != isPrefix(s1,s2)) {			if (isprefix)				System.err.println("Failure: says "+s1+" is NOT a prefix of "+s2);			else				System.err.println("Failure: says "+s1+" IS a prefix of "+s2);			return false;		} else			return true;	}	public static void main(String[] a) throws Exception {		boolean passes=true;		passes &= testisPrefix("a","abc",true);		passes &= testisPrefix("abc","abc",true);		passes &= testisPrefix("abcd","abc",false);		passes &= testisPrefix("a","a",true);		passes &= testisPrefix("","a",true);		passes &= testisPrefix("bcd","abcd",false);		passes &= testisPrefix("bc","abcd",false);		if (passes)			System.out.println("isPrefix passes these tests");		else			System.out.println("isPrefix fails these tests");	}}