Advertisement
desislava_topuzakova

Sum And Product

Apr 30th, 2018
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. package Exam28_29April;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class SumAndProduct {
  6.     public static void main(String[] agrs) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int n = Integer.parseInt(scanner.nextLine());
  9.         boolean isFound = true;
  10.         Here:
  11.         for (int a = 1; a <= 9; a++) {
  12.             for (int b = 9; b >= a; b--) {
  13.                 for (int c = 0; c <= 9; c++) {
  14.                     for (int d = 9; d >= c; d--) {
  15.  
  16.                         if (a + b + c + d == a * b * c * d && n % 10 == 5) {
  17.                             System.out.println(a + "" + b + "" + c + "" + d);
  18.                             isFound = false;
  19.                             break Here;
  20.                         } else if ((a * b * c * d) / (a + b + c + d) == 3 && n % 3 == 0) {
  21.                             System.out.println(d + "" + c + "" + b + "" + a);
  22.                             isFound = false;
  23.                             break Here;
  24.                         }
  25.                     }
  26.  
  27.                 }
  28.  
  29.             }
  30.  
  31.         }
  32.         if (isFound) {
  33.             System.out.println("Nothing found");
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement