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