Advertisement
desislava_topuzakova

Сбор или Произведение 25.06.2017

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