Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. public static void main(String[] args) {
  2. long[] num = new long[]{380564127,375809214,673982045,210437958,769082435};
  3. boolean minOnce=false,maxOnce=false;
  4. long min=num[0],max=num[0],minSum=0,maxSum=0;
  5. for (long value : num) {
  6. if (min > value) {
  7. min = value;
  8. }
  9. if (max<value){
  10. max = value;
  11. }
  12. }
  13. for (long value : num){
  14. if (min!=value || minOnce){
  15. maxSum+=value;
  16. }else{
  17. minOnce = true;
  18. }
  19. if (max!=value || maxOnce){
  20. minSum+=value;
  21. }else{
  22. maxOnce=true;
  23. }
  24. }
  25. System.out.println("Min sum:"+minSum+"\nMax sum:"+maxSum);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement