Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Exams;
- import java.util.Scanner;
- public class ExamMathPuzzle {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int key = Integer.parseInt(scanner.nextLine());
- boolean isNo = true;
- for (int first = 1; first <= 30; first++) {
- for (int second = 1; second <= 30; second++) {
- for (int third = 1; third <= 30; third++) {
- boolean check1 = first < second && second < third;
- boolean check2 = first + second + third == key;
- boolean check3 = first > second && second > third;
- boolean check4 = first * second * third == key;
- if (check1 && check2) {
- System.out.printf("%d + %d + %d = %d%n", first, second, third, key);
- isNo = false;
- }
- if (check3 && check4) {
- System.out.printf("%d * %d * %d = %d%n", first, second, third, key);
- isNo = false;
- }
- }
- }
- }
- if (isNo) {
- System.out.println("No!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement