Advertisement
marking2112

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

Jul 19th, 2018
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TrainingDemo {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int N = Integer.parseInt(scanner.nextLine());
  8.         int sum = 0;
  9.         int multi = 0;
  10.         for (int a = 1; a <= 30; a++) {
  11.             for (int b = 0; b <= 30; b++) {
  12.                 for (int c = 0; c <= 30; c++) {
  13.                     if (a < b && b < c) {
  14.                         sum = a + b + c;
  15.                         if (sum == N) {
  16.                             System.out.printf("%d + %d + %d = %d", a, b, c, N);
  17.                             System.out.println();
  18.                         }
  19.                     }
  20.                     if (a > b && b > c) {
  21.                         multi = a * b * c;
  22.                         if (multi == N) {
  23.                             System.out.printf("%d * %d * %d = %d", a, b, c, N);
  24.                             System.out.println();
  25.                         }
  26.                     }
  27.                 }
  28.             }
  29.         }
  30.         if (sum == 0 && multi == 0) {
  31.             System.out.println("No!");
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement