Advertisement
Lyubohd

Untitled

Jun 28th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. /**
  4.  * Created by karay on 6/25/2017.
  5.  */
  6. public class p06 {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         int num = Integer.parseInt(scanner.nextLine());
  10.         //int counter = 0;
  11.         boolean flag = false; // деклариране на флага
  12.  
  13.         for (int a = 1; a <= 30; a++) {
  14.             for (int b = 1; b <= 30; b++) {
  15.                 for (int c = 1; c <= 30; c++) {
  16.                     if (a < b && b < c) {
  17.                         if (a + b + c == num) {
  18.                             System.out.printf("%d + %d + %d = %d%n", a, b, c, num);
  19.                             //counter++;
  20.                             flag = true; // Промяна на стойността му на вярно
  21.                         }
  22.                     }
  23.                     if (a > b && b > c) {
  24.                         if (a * b * c == num) {
  25.                             System.out.printf("%d * %d * %d = %d%n", a, b, c, num);
  26.                             // counter++;
  27.                             flag = true; // Промяна на стойността му на вярно
  28.                         }
  29.                     }
  30.                 }
  31.             }
  32.         }
  33.        // if (counter < 1){
  34.        //     System.out.printf("No!");
  35.        // }
  36.             if (!flag) {                //Проверка на флага
  37.             System.out.println("No!");
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement