galinyotsev123

ProgBasicsExam1and2December2018-E06mathPuzzle

Jan 9th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class E06mathPuzzle{
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int n = Integer.parseInt(scanner.nextLine());
  8. int count =0;
  9.  
  10. for (int i = 1; i <= 30 ; i++) {
  11. for (int j = 1; j <=30 ; j++) {
  12. for (int k = 1; k <=30; k++) {
  13.  
  14.  
  15. if (i<=30 && j<=30 && k<=30) {
  16.  
  17. if (i < j && j < k) {
  18. if (i + j + k == n) {
  19. count++;
  20. System.out.printf("%d + %d + %d = %d%n", i, j, k, n);
  21. }
  22. }
  23.  
  24. if (i > j & j > k) {
  25. if (i * j * k == n) {
  26. count++;
  27. System.out.printf("%d * %d * %d = %d%n", i, j, k, n);
  28. }
  29. }
  30.  
  31. }
  32. }
  33. }
  34. }
  35.  
  36. if (count==0){
  37. System.out.println("No!");
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment