Advertisement
Ivakis

Сбор или произведение

Sep 7th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. public class demo {
  5. public static void main(String[] args) {
  6. Scanner scan = new Scanner(System.in);
  7.  
  8. int n = Integer.parseInt(scan.nextLine());
  9.  
  10. boolean isFound = false;
  11.  
  12. for (int a = 1; a <= 30; a++) {
  13. for (int b = 1; b <= 30; b++) {
  14. for (int c = 1; c <= 30; c++) {
  15.  
  16. if (((a < b) && (b < c)) && (a + b + c == n)) {
  17. isFound = true;
  18. System.out.printf("%d + %d + %d = %d\n", a, b, c, n);
  19. } else if (((a > b) && (b > c)) && (a * b * c == n)) {
  20. isFound = true;
  21. System.out.printf("%d * %d * %d = %d\n", a, b, c, n);
  22. }
  23. }
  24. }
  25. }
  26. if(!isFound){
  27. System.out.println("No!");
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement