Advertisement
Guest User

The song of the wheels

a guest
Jan 3rd, 2020
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TheSongOfTheWheels {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.  
  8.         int num = Integer.parseInt(scanner.nextLine());
  9.         int counter = 0;
  10.         int a = 0;
  11.         int b = 0;
  12.         int c = 0;
  13.         int d = 0;
  14.  
  15.  
  16.         for (int i = 1; i <= 9; i++) {
  17.             for (int j = 1; j <= 9; j++) {
  18.                 for (int k = 1; k <= 9; k++) {
  19.                     for (int l = 1; l <= 9; l++) {
  20.                         boolean isValid = i < j && k > l && (i * j) + (k * l) == num;
  21.                         if (isValid) {
  22.                             System.out.printf("%d%d%d%d ", i, j, k, l);
  23.                             counter++;
  24.                             if (counter == 4) {
  25.                                 a = i;
  26.                                 b = j;
  27.                                 c = k;
  28.                                 d = l;
  29.                             }
  30.                         }
  31.                     }
  32.                 }
  33.             }
  34.         }
  35.         if (counter >= 4) {
  36.             System.out.printf("%nPassword: %d%d%d%d", a, b, c, d);
  37.         } else {
  38.             System.out.print("No!");
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement