Advertisement
Deiancom

TheSongOfTheWheels

Oct 24th, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. package ProgrammingBasics.NestedLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class TheSongOfTheWheels {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int controlNumber = Integer.parseInt(scanner.nextLine());
  9.         int first = 0;
  10.         int second = 0;
  11.         int third = 0;
  12.         int fourth = 0;
  13.         int counter = 0;
  14.         boolean isTrue = false;
  15.         boolean newRow = false;
  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.                         if (i * j + k * l == controlNumber && i < j && k > l) {
  21.                             newRow = true;
  22.                             counter++;
  23.                             System.out.printf("%d%d%d%d ", i, j, k, l);
  24.                             if (counter == 4) {
  25.                                 isTrue = true;
  26.                                 first = i;
  27.                                 second = j;
  28.                                 third = k;
  29.                                 fourth = l;
  30.                             }
  31.                         }
  32.                     }
  33.                 }
  34.             }
  35.         }
  36.         if (newRow) {
  37.             System.out.println();
  38.         }
  39.         if (isTrue) {
  40.             System.out.printf("Password: %d%d%d%d", first, second, third, fourth);
  41.         } else {
  42.             System.out.print("No!");
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement