Welcome to ICSE Java Answers. Ask any questions you have related to Java and we will answer them.
Java is a registered trademark of Oracle. This site is in no way related to or endorsed by Oracle.

Store name and phone numbers in arrays, and search phone number by name

0 votes
Create any two arrays to store your seven friends' names and phone numbers. Accept a name by using Scanner class and print his/her phone number. If the name is not present in the list print an appropriate message
asked by AgrajC (5 points)
edited by Ranjith
Can i give answer in BufferedReader class

1 Answer

0 votes
import java.util.*;
public class arr
{
    public static void main(String args[])
    {
        Scanner Sc=new Scanner(System.in);
        String[] name=new String[7];
        long[] mob=new long[7];
        int temp=1;
        for(int i=0;i<7;i++)
        {
            System.out.print("Enter the name of friend");
            name[i]=Sc.nextLine();
            System.out.print("Enter the name of friend");
            mob[i]=Sc.nextLong();
        }
        System.out.println("Enter the name of friend whose number is to be searched");
        String ns=Sc.nextLine();
        for(int i=0;i<7;i++)
        {
            if(name[i].equalsIgnoreCase(ns))
            {
                System.out.println(name[i]+" = "+mob[i]);
                temp=0;
                break;
            }
        }
        if(temp==1)
        System.out.println("Search Unsuccessful");
    }
}
answered by dipesh (83 points)
...