/* ESc101 Laboratory Assignment Thursday of Week of 20/09/04 This program checks whether string 1 is a subset of string 2. */ import javabook.*; import java.awt.*; class SubstrCheck { StringBuffer str1, str2; MainWindow mainWindow; InputBox inputBox; // This method takes two string inputs from user and checks whether // str1 is a substring of str2. public void checkString() { String temp1, temp2; int strLength1, strLength2, index1, index2; inputBox = new InputBox(mainWindow); temp1 = inputBox.getString("Input the first string"); temp2 = inputBox.getString("Input the second string"); str1 = new StringBuffer(temp1); str2 = new StringBuffer(temp2); strLength1 = str1.length(); strLength2 = str2.length(); for(index1=0, index2=0; index2 < strLength2; index2++) { if (str1.charAt(index1) == str2.charAt(index2)) index1++; // We can advance in str1 if (index1 < strLength1) continue; // str1 is not finished else break; } if (index1 == strLength1) System.out.println(" First string is a subset of second string "); else System.out.println(" First string is not a subset of second string "); } } class soln7thur2 { public static void main(String[] args) { SubstrCheck substrCheck; substrCheck = new SubstrCheck(); substrCheck.checkString(); } }