Write an application that allows a user to enter two Strings

Write an application that allows a user to enter two Strings. Output the number of characters in the first String that also appear in the second String, and output those characters. Save the file as CountMatches.java. Don\'t forget to create the application/project CountMatchesTest. java Class that has the main method and an object to use the CountMatches class.

Solution

I have executed under netbeans IDE


package countmatchestest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;


public class CountMatchesTest {

String one,two;
  
public void readInput() throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.print(\"Enter string one:\\t\");
one = br.readLine();
System.out.print(\"Enter string two:\\t\");
two = br.readLine();
System.out.println(\"Number of matches = \"+countMatch(one,two));
  
}
public int countMatch(String one,String two){
int count =0,i;
for(i=0;i<one.length();i++){

if(one.charAt(i) == two.charAt(i)){
count++;

}
  
}
return count;
}
public static void main(String[] args) throws IOException {
  
CountMatchesTest c= new CountMatchesTest();
c.readInput();
}
  
}

 Write an application that allows a user to enter two Strings. Output the number of characters in the first String that also appear in the second String, and ou

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site