Computer Science, asked by yashgudiyal52, 9 months ago

Write a program to accept names and contact numbers of 25 people. The program should ask the user for the contact number and search for it in the contact numbers arrays .If the number is found , then the corresponding name is displayed otherwise a proper error message is displayed.​

Answers

Answered by ashutoshdubey1012197
1

import java.util.*;

public class Accept

{

Scanner sc = new Scanner(System.in);

public void main()

{

String st[]=new String[25];

String no[]=new String[25];

for(inti=0;i<25;i++)

{

System.out.println("Enter your name");

st[i]=sc.nextLine();

System.out.println("Enter your phone number");

no[i]=sc.nextLine();

}

System.out.println("Enter the phone number");

String se=new String();

for(int j=0;j<25;j++)

{

if(se==no[j])

{

System.out.println("The name is "+st[j]);

break;

}

continue;

System.out.println("Invalid");

}

}

}

Comments: continue;

System.out.println("Invalid");  

the above statement may seem little unorthodox but it will work making it more efficient.

Similar questions