Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Exan1to2Dec18;
- import java.util.Scanner;
- public class MathPuzzle {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int key = Integer.parseInt(scanner.nextLine());
- int counter = 0;
- for (int a = 1; a <= 30; a++) {
- for (int b = 1; b <= 30; b++) {
- for (int c = 1; c <= 30; c++) {
- if (a + b + c == key) {
- if (a < b && b < c) {
- System.out.printf("%d + %d + %d = %d%n", a, b, c, key);
- }
- } else if (a * b * c == key) {
- if (a > b && b > c) {
- System.out.printf("%d * %d * %d = %d%n", a, b, c, key);
- }
- } else {
- counter++;
- }
- }
- }
- }
- if (counter >= 30 * 30 * 30) {
- System.out.println("No!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement