svetlozar_kirkov

Stuck Numbers [Java Exam]

Oct 3rd, 2015
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. package com.sve;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Scanner;
  5.  
  6. public class Playground {
  7.  
  8.     public static void main(String[] args) {
  9.         Scanner scan = new Scanner(System.in);
  10.         int count = Integer.parseInt(scan.nextLine());
  11.         int[] numbers = Arrays.stream(scan.nextLine().split("\\s+"))
  12.                 .mapToInt(Integer::parseInt)
  13.                 .toArray();
  14.         boolean found = false;
  15.         if (numbers.length < 4) {
  16.             System.out.println("No");
  17.             return;
  18.         }
  19.         for (int i = 0; i < numbers.length; i++) {
  20.             int first = numbers[i];
  21.             for (int j = 0; j < numbers.length; j++) {
  22.                 int second = numbers[j];
  23.                 if (second == first) {
  24.                     continue;
  25.                 }
  26.                 for (int k = 0; k < numbers.length; k++) {
  27.                     int third = numbers[k];
  28.                     if (third == second || third == first) {
  29.                         continue;
  30.                     }
  31.                     for (int l = 0; l < numbers.length; l++) {
  32.                         int fourth = numbers[l];
  33.                         if (fourth == third || fourth == second || fourth == first) {
  34.                             continue;
  35.                         }
  36.                         String firstPair = first + "" + second;
  37.                         String secondPair = third + "" + fourth;
  38.                         if (firstPair.equals(secondPair)) {
  39.                             System.out.println(first + "|" + second + "==" + third + "|" + fourth);
  40.                             found = true;
  41.                         }
  42.                     }
  43.                 }
  44.             }
  45.         }
  46.         if (found == false) {
  47.             System.out.println("No");
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment