nevenailievaa

03. Lucky Numbers

Mar 6th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. package F06NestedLoops.MoreExercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class T03 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int n = Integer.parseInt(scanner.nextLine());
  10.  
  11.         for (int a = 1; a <= 9; a++) {
  12.             for (int b = 1; b <= 9; b++) {
  13.                 for (int c = 1; c <= 9; c++) {
  14.                     for (int d = 1; d <= 9; d++) {
  15.                         int sumFirstTwo = a + b;
  16.                         int sumLastTwo = c + d;
  17.  
  18.                         if (sumFirstTwo == sumLastTwo && n % sumFirstTwo == 0) {
  19.                             System.out.printf("%d%d%d%d ", a, b, c, d);
  20.                         }
  21.                     }
  22.                 }
  23.             }
  24.         }
  25.     }
  26. }
Add Comment
Please, Sign In to add comment