Computer Science, asked by karanjaitaran, 1 month ago

Given five positive integers, find the minimum and maximum values that can be calculated by summing (10 marks)
exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers.

Answers

Answered by bashamahaboob837
0

Answer:

Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum

values as a single line of two space-separated long integers.

For example, . Our minimum sum is  and our maximum sum is . We would print

16 24


bashamahaboob837: I think it is useful to you
Answered by paul141296
0

Answer:

import java.io.*;

import java.math.*;

import java.security.*;

import java.text.*;

import java.util.*;

import java.util.concurrent.*;

import java.util.regex.*;

import java.util.Arrays;

public class Solution {

public static void main(String args[]) {

Scanner sc = new Scanner(System.in);

// initialize array

long arr[] = new long[5];

long sum = 0;

// array elements

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

arr[i] = sc.nextLong();

sum += arr[i];

}

// Sorting the array and storing the minimum and maximum values

Arrays.sort(arr);

long min = arr[4];

long max = arr[0];

long minSum = sum - min;

long maxSum = sum - max;

System.out.println(minSum + " " + maxSum);

}

}

Similar questions