lent me a hint for this problem please? (Java) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

lent me a hint for this problem please? (Java)

Write a Java program to find the two elements from a given array of positive and negative numbers such that their sum is closest to zero.

18th Jun 2019, 10:31 AM
Tzion
Tzion - avatar
2 Answers
0
~ swim ~ hmm,i only know using double forloop to find the sum ,but dont know how to add 1,-1
18th Jun 2019, 10:36 PM
Tzion
Tzion - avatar
0
> "how to add 1,-1" arr[1,-1,2,-3] sum = arr[0] + arr[1] ; //1 + (-1)
19th Jun 2019, 6:29 AM
zemiak