Advertisement
Guest User

One.java

a guest
Feb 29th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class One{
  4.     public static void main(String[] args) {
  5.         Scanner myObj = new Scanner(System.in);
  6.         System.out.println("Enter the five numbers: ");
  7.         long num[] = new long[5];
  8.        
  9.         for (int i = 0; i <= num.length; i++) {
  10.             num[i] = myObj.nextLong();
  11.         }
  12.         boolean minOnce=false,maxOnce=false;
  13.         long min=num[0],max=num[0],minSum=0,maxSum=0;
  14.        
  15.         for (long value : num) {
  16.             if (min > value) {
  17.                 min = value;
  18.             }
  19.             if (max<value){
  20.                 max = value;
  21.             }
  22.         }
  23.         for (long value : num){
  24.             if (min!=value || minOnce){
  25.                 maxSum+=value;
  26.             }else{
  27.                 minOnce = true;
  28.             }
  29.             if (max!=value || maxOnce){
  30.                 minSum+=value;
  31.             }else{
  32.                 maxOnce=true;
  33.             }
  34.         }
  35.         System.out.println("Min sum:"+minSum+"\nMax sum:"+maxSum);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement