public class CharMatch {
private void matchString(String s1, String s2) {
int count = 0;
int len1 = s1.length();
int len2 = s2.length();
for (int i = 0; i < len2; i++) {
for (int j = 0; j < len1; j++) {
if (s2.charAt(i) == s1.charAt(j)) {
count++;
}
if (count == len2) {
System.out.print("True");}
}
}
}
public static void main(String args[]) throws IOException {
CharMatch cm = new CharMatch();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter First String");
String a = br.readLine();
System.out.println("Enter Second String");
String b= br.readLine();
cm.matchString(a,b);
}
}
I was writing this code to input two string for example input: s1="Hello world" s2:"woeh"
then the output should be true if all the characters in s2
matches at least once in s1
. This is the code which I wrote, but I am not getting at perfect output as desired.