String Matched if input as a bit of 0`s and 1`s

String Matched if input as a bit of 0`s and 1`s
SOURCE : StringMatchedCount.java


public class StringMatchedCount {

public static void main(String[] args) {

String s1 = "1101100010101";
String s2 = "101100000000000";
int count = 0;
int n = 0;
if (s1.length() > s2.length())
n = s1.length() - s2.length();
else {
n = s2.length() - s1.length();
}
for (int i = 0; i < n; i++) {

if (s1.charAt(i) == s2.charAt(i)) {

if (s1.charAt(i) == '1') {

count++;
}
}

}
System.out.println(count);
}

}


INPUT

String s1 = "1101100010101";
String s2 = "101100000000000";



OUTPUT

1







Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment