arrayq3

Ads

 
 

Share on Google+Share on Google+

arvind
arrayq3
1 Answer(s)      6 years and 3 months ago
Posted in : Java Magazine

Write a program that accepts two arrays, an array of fruit names and an array of price of fruits, and a fruit name and returns the price of the fruit. (Assume that a price in the second array corresponds to the price of the fruit at the same position in the first list) i. e. if inputs are {‚??Grapes‚??, ‚??Orange‚??, ‚??Apple‚??‚?¶} and {23.50, 35.00, 12.40‚?¶} then price of Grapes is 23.50

Ads
View Answers

March 1, 2011 at 4:08 PM


import java.util.*;
class ArrayExample4 
{
    public static void main(String[] args) 
    {
        Scanner input=new Scanner(System.in);
        System.out.println("Enter fruit names: ");
        String fruit[]=new String[3];
        double price[]=new double[3];
        for(int i=0;i<fruit.length;i++){
            fruit[i]=input.next();
        }
        System.out.println("Enter fruit prices: ");
        for(int i=0;i<price.length;i++){
            price[i]=input.nextDouble();
        }
        System.out.println("Enter fruit name: ");
        String f=input.next();
        int index=0;
        for(int i=0;i<fruit.length;i++){
        if(fruit[i].equals(f)){
            index=i;
        }
        }
        System.out.println("price of "+f+" is "+price[index]);

    }
}

Ads









Related Tutorials/Questions & Answers:
arrayq3
arrayq3  Write a program that accepts two arrays, an array of fruit names and an array of price of fruits, and a fruit name and returns the price of the fruit. (Assume that a price in the second array corresponds to the price
Tutorials   
Java Spring Hibernate Struts Training Default value of path variable in Windows 7 Windows 7 refresh DNS 550 Access denied - Invalid HELO name (See RFC2821 4.1.1.1) how to change a column data in a every row in a text file in java cursor location what is the Advantages moqui framework vs other frameworks what is the difference between moqui framework vs other frameworks Develop Bulk SMS sender Bundle of servers interface ALU Computer Term How to find the size of a dynamic webpage using java... eg : Youtube........ Question in Create Arraylist ? active window means 1024 bytes equals to can a volatile memory loss data on power cut What is E-Learning? What is E-Learning? What is hacker? different types of storage devices of a computer Examples of optical disk Main job of cpu Main memory is also known as Define computer software. connection between your computer and local isp which part of the cpu does math calculations What is procedure Where i can use UNIX Operating System? What was ENIAC One byte consists of how many bits? What is the use of Bluetooth technology basic function of computer system how to measure data transfer speed GIGO Full Form What is parallel port where are program instructions and data values stored Nible is a computer network is referred as The input device used by computer is The product of data processing is The CPU(Central processing unit)consist of One-thousand of a second is called Alternate facilities of programs, data files, hardware equipment, etc. One-Millionth of a second is referred as Storage medium that loses its contents A LSI chip contains the entire CPU of computer except main memory is called ascending order of a data hierarchy Combining records from two or more orders files into a single ordered file is called Computer questions for Bank PO Exams and upsc competitive exams characteristics of a modem computer

Ads

 
Advertisement null

Ads