Advertisement
nevenailievaa

12. The song of the wheels

Mar 6th, 2024
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. package NestedLoopsMoreEx;
  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.  
  9.         int M = Integer.parseInt ( scanner.nextLine () );
  10.  
  11.         int passCount = 0;
  12.         int fourthComb = 0;
  13.  
  14.         int x1 = 1;
  15.         int x2 = 1;
  16.         int x3 = 1;
  17.         int x4 = 1;
  18.  
  19.         for ( int a = 1; a <= 9; a++){
  20.             for ( int b = 1; b <= 9; b++) {
  21.                 for (int c = 1; c <= 9; c++) {
  22.                     for (int d = 1; d <= 9; d++) {
  23.                         if (a < b && c >d && a * b + c * d == M){
  24.                             passCount++;
  25.                             System.out.printf ( "%d%d%d%d ", a, b, c, d );
  26.  
  27.                             if (passCount == 4){
  28.                                 x1 = a;
  29.                                 x2 = b;
  30.                                 x3 = c;
  31.                                 x4 = d;
  32.                             }
  33.                         }
  34.                     }
  35.                 }
  36.             }
  37.         }
  38.         if (passCount >= 4){
  39.             System.out.println ();
  40.             System.out.printf ( "Password: %d%d%d%d", x1, x2, x3, x4 );
  41.         } else {
  42.             System.out.println ();
  43.             System.out.print ( "No!" );
  44.         }
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement