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();
}
}
![Exception in thread "main" java.util.NoSuchElementException: No line found
at
at LabProgram.main (LabProgram.java:9)
java.base/java.util.Scanner.nextLine
Output differs. See highlights below. Special character legend
Input crash crush
Your output
2:Compare output
Expected output 4 characters matche
Exception in thread "main" java.util.No SuchElementException: No line found
at java.base/java.util.Scanner.nextLine (Scanner.java:1651)
at LabProgram.main (LabProgram.java:9)
Output differs. See highlights below. Special character legend
Input cat catnip
Your output
(Scanner.java:1651)
Expected output 3 characters matche](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Faad9e4ed-ed50-4fe3-96ca-72ed3d364f6f%2Fe1d5ba75-9b92-48b5-9e70-91b8fe5b8c3a%2Favnez9_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)