Advertisement
Deiancom

Math Puzzle

Mar 2nd, 2020
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class MathPuzzle06 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int controlNumber = Integer.parseInt(scanner.nextLine());
  8.  
  9.         boolean plus = true;
  10.         boolean multiply = true;
  11.         for (int i = 1; i <= 30; i++) {
  12.             for (int j = 1; j <= 30; j++) {
  13.                 for (int k = 1; k <= 30; k++) {
  14.                     if (i < j && j < k) {
  15.                         if (i + j + k == controlNumber) {
  16.                             plus = false;
  17.                             System.out.printf("%d + %d + %d = %d%n", i, j, k, controlNumber);
  18.                         }
  19.                     }
  20.                     if (i > j && j > k) {
  21.                         if (i * j * k == controlNumber) {
  22.                             multiply = false;
  23.                             System.out.printf("%d * %d * %d = %d%n", i, j, k, controlNumber);
  24.                         }
  25.                     }
  26.                 }
  27.             }
  28.         }
  29.         if (plus && multiply) {
  30.             System.out.println("No!");
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement