Advertisement
Guest User

Java StuckNumbers

a guest
Feb 22nd, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class StuckNumbers {
  4.  
  5.     public static void main(String[] args) {
  6.        
  7.         // Read the input sequence of n integers
  8.         Scanner scanner = new Scanner(System.in);
  9.         int n = scanner.nextInt();
  10.         int[] nums = new int[n];
  11.         for (int i = 0; i < nums.length; i++) {
  12.             nums[i] = scanner.nextInt();
  13.         }
  14.        
  15.         // Find and print all stuck numbers {a, b, c, d}
  16.         int count = 0;
  17.         for (int num1 = 0; num1 < nums.length; num1++) {
  18.             for (int num2 = 0; num2 < nums.length; num2++) {
  19.                 for (int num3 = 0; num3 < nums.length; num3++) {
  20.                     for (int num4 = 0; num4 < nums.length; num4++) {
  21.                         int a = nums[num1];
  22.                         int b = nums[num2];
  23.                         int c = nums[num3];
  24.                         int d = nums[num4];
  25.                         if (a != b && a != c & a != d &&
  26.                             b != c && b != d && c != d) {
  27.                             String first = "" + a + b;
  28.                             String second = "" + c + d;
  29.                             if (first.equals(second)) {
  30.                                 System.out.printf("%d|%d==%d|%d\n",
  31.                                     a, b, c, d);
  32.                                 count++;
  33.                             }
  34.                         }
  35.                     }
  36.                 }              
  37.             }
  38.         }
  39.        
  40.         if (count == 0) {
  41.             System.out.println("No");
  42.         }
  43.     }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement