Computer Science, asked by rockbottom619rip, 3 months ago

Accept a name (n) to search in a file named friends.txt. Search for the name in the text file and display the

message “name found in the file” otherwise display “search unsuccessful” if the name is not in the list.

Assume that names stored in the file are in upper case only. The method declaration is as follows:

void findName(String n);

I need a genuine solution, so please do not write gibberish just to get the points. A humble request.​

Answers

Answered by hellboysam
2

Answer:

import java.util.*;

class LinearSerch

{

public static void main(String args[])

{Scanner ob=new Scanner(System.in);

Sopl("enter the value of friends.txt");

String f=ob.nextLine(),r="";

void findName(String n)

{

int y=0;

for(int i=0;1<=f.length();i++)

{

char ch=f.charAt(i);

if(ch!=32)

r=r+ch;

else

{

if(r.equalsIgnorecase(n))

y=1;

sopl("search successful ");r="";

}

if(y==0)

sopl("search unsuccessful ");

}}}

Similar questions