Question
Description Write a Java program that goes shopping. You receive a credit C at a local store and would like to buy two items. You
Description
Write a Java program that goes shopping. You receive a credit C at a local store and would like to buy two items. You first walk through the store and create a list L of all available items. From this list you would like to buy two items that add up to the entire value of the credit. The solution you provide will consist of the two integers indicating the positions of the items in your list (smaller number first).
Input
The first line of input gives the number of cases, N. N test cases follow. For each test case there will be:
One line containing the value C, the amount of credit you have at the store.
One line containing the value I, the number of items in the store.
One line containing a space separated list of I integers. Each integer P indicates the price of an item in the store.
Each test case will have exactly one solution.
Output
For each test case, output one line containing Case #x: followed by the indices of the two items whose price adds up to the store credit. For this problem, the index number is the position of the item - e.g., the second item is index 2. The lower index should be output first.
Limits
N <= 10, 5 <= C <= 1000, 1 <= P <= 1000, 3 <= I <= 100
Sample Input
3 100 3 5 75 25 200 7 150 24 79 50 88 345 3 8 8 2 1 9 4 4 56 90 3
Sample Output
Case #1 2 3 Case #2 1 4 Case #3 4 5
Additional Information
You should use a Scanner to read the input values.
Do not prompt for input. The input will be there.
You should use System.out.println() to generate your output.
The output line has to match exactly.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started