SophiYo

Ex.06MathPuzzle

Dec 16th, 2018
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. package DecemberFirst;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class O6MathPuzzle {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int n = Integer.parseInt(scanner.nextLine());
  9.         int count1 = 0;
  10.         int count2 = 0;
  11.  
  12.  
  13.         for (int i = 1; i <=30 ; i++) {
  14.             for (int j = 1; j <= 30; j++) {
  15.                 for (int k = 1; k <= 30 ; k++) {
  16.  
  17.                     if ( i + j + k == n ) {
  18.  
  19.                         if (i < j && j < k) {
  20.                             count1 ++;
  21.  
  22.                             System.out.printf("%d + %d + %d = %d%n", i, j, k, n);
  23.                         }
  24.  
  25.                     } else if ( (i*j*k)==n) {
  26.  
  27.                         if (i>j && j >k) {
  28.                             count2++;
  29.  
  30.                             System.out.printf("%d * %d * %d = %d%n", i, j, k, n);
  31.                         }
  32.                     }
  33.  
  34.                 }
  35.             }
  36.         }
  37.  
  38.         if ( count1 == 0 && count2 == 0) {
  39.             System.out.println("No!");
  40.         }
  41.  
  42.  
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment