
Write a Java program that prompts the user to enter a name. The program will compare the name with a list of names from a file named Names.txt. The program will then display the total number of names in the file that matches with the name given by the user. Use classes and methods from the java.io package for all input.

Java match name:
import java.io.*;
class MatchName{
public static void main(String[] args)throws Exception
{
int count=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter name: ");
String name=br.readLine();
BufferedReader reader=new BufferedReader(new FileReader(new File("C:/names.txt")));
String names="";
while((names = reader.readLine()) != null) {
if(names.equals(name)){
count++;
}
}
System.out.println("Total number of names in the file that matches with the given name: "+count);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.