Advertisement
Osiris1002

Untitled

Dec 13th, 2022
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. package IZPIT;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Sum_And_Product {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.  
  9.         int n = Integer.parseInt(scan.nextLine());
  10.  
  11.         boolean nova = false;
  12.  
  13.         for (int a = 1; a <= 9; a++) {
  14.             for (int b = 9; b >= a; b--) {
  15.                 for (int c = 0; c <= 9; c++) {
  16.                     for (int d = 9; d >= c; d--) {
  17.                         int sum = a + b + c + d;
  18.                         int product = a * b * c * d;
  19.                         if (sum == product && n % 10 == 5) {
  20.                             System.out.printf("%d%d%d%d%n", a, b, c, d);
  21.                             nova = true;
  22.                             break;
  23.                         } else if (product / sum == 3 && n % 3  == 0) {
  24.                             System.out.printf("%d%d%d%d%n", d, c, b, a);
  25.                             nova = true;
  26.                             break;
  27.                         }
  28.                     }
  29.                     if(nova){
  30.                         break;
  31.                     }
  32.                 }
  33.                 if(nova){
  34.                     break;
  35.                 }
  36.             }
  37.             if(nova){
  38.                 break;
  39.             }
  40.         }
  41.         if(nova){
  42.             System.out.print("");
  43.         }else {
  44.             System.out.println("Nothing found");
  45.         }
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement