Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone explain why I ' m getting this error. I need to input the values just like this. 4 1 5 3 5 6

Can someone explain why I'm getting this error. I need to input the values just like this.
4
1535679
14
03163
11
0641-864510
16
16-81461045
16
this is the code:
import java.util.;
class Main
static class Pair
int first;
int second;
Pairint first, int second
this.first first;
this.second second;
static Pair getCandidatePairint A int target
HashSet set new HashSet;
for int num : A
int complement target num;
if setcontainscomplement
return new Pairnum complement;
set.addnum;
return new Pair;
public static void mainString args
Scanner scanner new ScannerSystemin;
int t scanner.nextInt;
scanner.nextLine; Consume newline
for int i ; i t; i
String statusAndSize scanner.nextLinesplit;
int status Integer.parseIntstatusAndSize;
int size Integer.parseIntstatusAndSize;
int groceries new intsize;
String groceriesString scanner.nextLinesplit;
for int j ; j size; j
groceriesj Integer.parseIntgroceriesStringj;
int target scanner.nextInt;
scanner.nextLine; Consume newline
Pair pair;
if status
pair getCandidatePairSortedgroceries target;
else
pair getCandidatePairgroceries target;
if pairfirst && pair.second
System.out.printlnTest case # i : Spend target dollars by buying the groceries with Math.minpairfirst, pair.second dollars and Math.maxpairfirst, pair.second dollars.";
else
System.out.printlnTest case # i : No way you can spend exactly target dollars.";
static Pair getCandidatePairSortedint A int target
int left right Alength ;
while left right
int sum Aleft Aright;
if sum target
return new PairAleft Aright;
else if sum target
left;
else
right;
return new Pair;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

Students also viewed these Databases questions

Question

What is meant by Non-programmed decision?

Answered: 1 week ago

Question

c. What were you expected to do when you grew up?

Answered: 1 week ago

Question

4. Describe how cultural values influence communication.

Answered: 1 week ago

Question

3. Identify and describe nine cultural value orientations.

Answered: 1 week ago