Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. package Exams;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class ExamMathPuzzle {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int key = Integer.parseInt(scanner.nextLine());
  10. boolean isNo = true;
  11.  
  12. for (int first = 1; first <= 30; first++) {
  13. for (int second = 1; second <= 30; second++) {
  14. for (int third = 1; third <= 30; third++) {
  15.  
  16. boolean check1 = first < second && second < third;
  17. boolean check2 = first + second + third == key;
  18. boolean check3 = first > second && second > third;
  19. boolean check4 = first * second * third == key;
  20.  
  21. if (check1 && check2) {
  22. System.out.printf("%d + %d + %d = %d%n", first, second, third, key);
  23. isNo = false;
  24. }
  25. if (check3 && check4) {
  26. System.out.printf("%d * %d * %d = %d%n", first, second, third, key);
  27. isNo = false;
  28. }
  29.  
  30.  
  31. }
  32. }
  33. }
  34.  
  35. if (isNo) {
  36. System.out.println("No!");
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement