
Search for a name
Write a program to accept an array of names and a name and check whether the
name is present in the array. Return the count of occurrence. Use the following
array as input
{?Dave?, ?Ann?, ?George?, ?Sam?, ?Ted?, ?Gag?, ?Saj?, ?Agati?, ?Mary?, ?Sam?,
?Ayan?, ?Dev?, ?Kity?, ?Meery?, ?Smith?, ?Johnson?, ?Bill?, ?Williams?, ?Jones?,
?Brown?, ?Davis?, ?Miller?, ?Wilson?, ?Moore?, ?Taylor, ?Anderson?, ?Thomas?,
?Jackson?}

import java.io.*; import java.util.StringTokenizer;
public class CountOccurance { public static void main(String args[])throws Exception { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr);
print("code sample");
System.out.println("ENTER ARRAY OF NAMES:");
String arrNames=br.readLine();
StringTokenizer st1=new StringTokenizer(arrNames);
System.out.println("ENTER THE NAME TO BE SEARCHED:");
String name=br.readLine();
int countNoOccurance=0;
while(st1.hasMoreTokens())
{
if(name.equalsIgnoreCase(st1.nextToken()))
{
countNoOccurance++;
}
}
System.out.println("THE NAME "+name+" HAS BEEN APPEARED "+countNoOccurance+" NO. OF TIMES");
}
}
*Sayem*
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.