import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print(" "); String s1 = sc.nextLine(); System.out.print(""); String s2 = sc.nextLine(); int minLen = Math.min(s1.length(), s2.length()); int matchCount = 0; for (int i = 0; i < minLen; i++) { if (s1.charAt(i) == s2.charAt(i)) { matchCount++; } } if (matchCount == 1) { System.out.println("1 character matches"); } else { System.out.println(matchCount + " characters match"); } sc.close(); } }
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print(" ");
String s1 = sc.nextLine();
System.out.print("");
String s2 = sc.nextLine();
int minLen = Math.min(s1.length(), s2.length());
int matchCount = 0;
for (int i = 0; i < minLen; i++) {
if (s1.charAt(i) == s2.charAt(i)) {
matchCount++;
}
}
if (matchCount == 1) {
System.out.println("1 character matches");
} else {
System.out.println(matchCount + " characters match");
}
sc.close();
}
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images