Computer Science, asked by bhavyanarahari1512, 1 day ago

the game company has designed an online lottery game, bingo. In this game N number cards are displayed. Each card has a value in it. The value can be negative or positive. The player must choose 2 cards. To win the game, the peoduct of the values of the two cards must be the maximum value possible for any pair of cards in the display. The winning amount will be the sum of the two values of the two cards whose product value is maximum ​

Answers

Answered by jatinsingh746
0

Answer:

xjjdhddhdhdhddjdjdjdjdhdhd

Answered by shilpa85475
2

We consider N as the number of cards that are displayed in the game

The Input is 7  

Numbers are 9 -3 8 10 8 -7-6  

The output is 19

 

Explanation:

import java.util.Scanner;

public class game {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

int nCards = scan.nextInt(); //read input number of cards that is we will give 7 in this case.

int[] cards = new int[nCards];  //declare an array to store the card values that are assign as both negative and postive values

for(int i=0;i<nCards;i++) {

 cards[i] = scan.nextInt();  //read the card values that are inserted in the array above

}

int maxProduct = 0; //integer value needed to store the max product of 2 cards

int c1=0,c2=0;  //two individual cards whose product is maximum of all

//determine max product and then assign cards values to the two cards respectively to card1 and card2

for(int i=0;i<nCards-1;i++) {

 for(int j=i+1;j<nCards;j++) {

  if(cards[i]*cards[j] > maxProduct) {

   maxProduct = cards[i] * cards[j];

   c1 = cards[i];

  c2 = cards[j];

  }

 }

}

//sum of 2 highest products of the cards

int sum = card1 + card2;

System.out.println(sum); //display the output

}

}

Similar questions