Largest Product of Two Elements of An Unsorted Array
Largest Product of Two Elements of An Unsorted Array
import java.util.*;
class Product
int n=sc.nextInt();
for(int K=0;K<n;K++)
nums[K]=sc.nextInt();
int largest=0;
int secondLargest=0;
{
// If the current element is greater than the largest, update both .
secondLargest = largest;
largest = nums[i];
// If the current element is greater than the second largest, update only
secondLargest.
secondLargest = nums[i];
int smallest=0;
int secondSmallest=0;
//If the current element is smaller than the smallest, update both.
secondSmallest = smallest;
smallest = nums[j];
{
//If the current elementis smaller than tghe second smallest,update only secondSmallest.
secondSmallest = nums[j];
//To check if two positive elements or two negative elements which have highest product.
else
//OUTPUT
39
-88
65
21
-90
101
7920