Guest User

Untitled

a guest
May 3rd, 2018
74
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package L11Arrays;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.Arrays;
  7.  
  8. public class Ex04TripleSum01 {
  9.     private static BufferedReader reader;
  10.     private static int[] numbers;
  11.     private static int counter;
  12.  
  13.     public static void main(String[] args) throws IOException {
  14.         reader = new BufferedReader(new InputStreamReader(System.in));
  15.         counter = 0;
  16.         numbers = Arrays.stream(reader.readLine().split("\\s+"))
  17.                 .mapToInt(Integer::parseInt)
  18.                 .toArray();
  19.  
  20.         for (int i = 0; i < numbers.length; i++) {
  21.             for (int j = i + 1; j < numbers.length; j++) {
  22.                 int a = numbers[i];
  23.                 int b = numbers[j];
  24.                 int c = a + b;
  25.                 if (anyMatch(c)) {
  26.                     System.out.println(String.format("%d + %d == %d", a, b, c));
  27.                     counter++;
  28.                 }
  29.             }
  30.         }
  31.  
  32.         if (counter == 0) {
  33.             System.out.println("No");
  34.         }
  35.     }
  36.  
  37.     private static boolean anyMatch(int c) {
  38.         for (int i = 0; i < numbers.length; i++) {
  39.             if (numbers[i] == c) {
  40.                 return true;
  41.             }
  42.         }
  43.         return false;
  44.     }
  45. }
RAW Paste Data