Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Exam;
- 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());
- boolean flag1 = false;
- boolean flag2 = false;
- for (int i = 1; i <= 30; i++) {
- for (int j = 1; j <= 30; j++) {
- for (int k = 1; k <= 30; k++) {
- if ((i + j + k == key)) {
- if (i < j && j < k) {
- flag1 = true;
- System.out.println(i + " + " + j + " + " + k + " = " + key);
- }
- }
- if(i*j*k==key){
- if (i > j && j > k) {
- flag2 = true;
- System.out.println(i + " * " + j + " * " + k + " = " + key);
- }
- }
- }
- }
- }
- if(flag1 == false && flag2 == false){
- System.out.println("No!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement