borkins

Exam Jan-2016 - 06. Sum 3 Numbers

May 11th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. /**
  2.  * Project: Exam_101_January_2016 - created by borkins on 2017-05-03.
  3.  */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class _06_SumThreeNumbers
  8. {
  9.     public static void main(String[] args)
  10.     {
  11.         Scanner console = new Scanner(System.in);
  12.    
  13.         int n1 = Integer.parseInt(console.nextLine());
  14.         int n2 = Integer.parseInt(console.nextLine());
  15.         int n3 = Integer.parseInt(console.nextLine());
  16.    
  17.         int a = getMin(getMin(n1, n2), n3);
  18.         int c = getMax(getMax(n1, n2), n3);
  19.         int b = 0;
  20.    
  21.         if (a == n1) {
  22.             b = getMin(n2, n3);
  23.         }
  24.         else if (a == n2) {
  25.             b = getMin(n1, n3);
  26.         }
  27.         else if (a == n3) {
  28.             b = getMin(n1, n2);
  29.         }
  30.    
  31.         System.out.println((a + b == c) ? (a + " + " + b + " = " + c) : "No");
  32.     }
  33.    
  34.     public static int getMin(int a, int b) {
  35.         if (a <= b) return a;
  36.         return b;
  37.     }
  38.    
  39.     public static int getMax(int a, int b) {
  40.         if (a >= b) return a;
  41.         return b;
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment