Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class MathPuzzle06 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int controlNumber = Integer.parseInt(scanner.nextLine());
- boolean plus = true;
- boolean multiply = true;
- for (int i = 1; i <= 30; i++) {
- for (int j = 1; j <= 30; j++) {
- for (int k = 1; k <= 30; k++) {
- if (i < j && j < k) {
- if (i + j + k == controlNumber) {
- plus = false;
- System.out.printf("%d + %d + %d = %d%n", i, j, k, controlNumber);
- }
- }
- if (i > j && j > k) {
- if (i * j * k == controlNumber) {
- multiply = false;
- System.out.printf("%d * %d * %d = %d%n", i, j, k, controlNumber);
- }
- }
- }
- }
- }
- if (plus && multiply) {
- System.out.println("No!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement