Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class One{
- public static void main(String[] args) {
- Scanner myObj = new Scanner(System.in);
- System.out.println("Enter the five numbers: ");
- long num[] = new long[5];
- for (int i = 0; i <= num.length; i++) {
- num[i] = myObj.nextLong();
- }
- boolean minOnce=false,maxOnce=false;
- long min=num[0],max=num[0],minSum=0,maxSum=0;
- for (long value : num) {
- if (min > value) {
- min = value;
- }
- if (max<value){
- max = value;
- }
- }
- for (long value : num){
- if (min!=value || minOnce){
- maxSum+=value;
- }else{
- minOnce = true;
- }
- if (max!=value || maxOnce){
- minSum+=value;
- }else{
- maxOnce=true;
- }
- }
- System.out.println("Min sum:"+minSum+"\nMax sum:"+maxSum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement