Write a program to accept five names and another array to accept
their respective telephone numbers. Search for a telephone
number input by the user, in the list. If found display “Search
successful” and print the name along with the telephone number,
otherwise display “Search unsuccessful”.
Answers
Answered by
1
import java.util.Scanner;
public class arrayprogram
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int x=0;
String a[]= new String[10];
long b[]= new long[10];
System.out.println("Enter Elements");
for(int i=0;i<10;i++)
{
System.out.println("Names");
b[i]=sc.nextLine();
System.out.println("Telephone Numbers");
a[i]=sc.nextLong();
}
System.out.println("Enter item to search");
String n=sc.nextLine();
for(int j=0;j<10;j++)
{
if(n.compareToIgnoreCase(b[j])==0)
{
System.out.println("Telephone number"+a[j]);
x++;
break;
}
}
if(x<1)
System.out.println("Inavalid");
}
}
Similar questions
English,
3 months ago
Accountancy,
3 months ago
Chemistry,
3 months ago
Chemistry,
6 months ago
Math,
11 months ago