Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DecemberFirst;
- import java.util.Scanner;
- public class O6MathPuzzle {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int count1 = 0;
- int count2 = 0;
- 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 == n ) {
- if (i < j && j < k) {
- count1 ++;
- System.out.printf("%d + %d + %d = %d%n", i, j, k, n);
- }
- } else if ( (i*j*k)==n) {
- if (i>j && j >k) {
- count2++;
- System.out.printf("%d * %d * %d = %d%n", i, j, k, n);
- }
- }
- }
- }
- }
- if ( count1 == 0 && count2 == 0) {
- System.out.println("No!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment