Advertisement
Ivakis

The song of wheels

Oct 25th, 2017
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class demo {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6.  
  7. int n = Integer.parseInt(scan.nextLine());
  8. int count = 0;
  9.  
  10. String password = "";
  11. boolean passwordIsFound = false;
  12.  
  13. for (int i = 1; i <= 9; i++) {
  14. for (int j = 1; j <= 9; j++) {
  15. for (int k = 1; k <= 9; k++) {
  16. for (int l = 1; l <= 9; l++) {
  17.  
  18. if (i < j && k > l) {
  19. if (i * j + k * l == n) {
  20. count++;
  21. System.out.printf("%d%d%d%d ", i, j, k, l);
  22. if (count == 4) {
  23. // password = i + "" + j + "" + k + "" + l + ""; OK
  24. //password = "i" + "j" + "k" + "l"; Not OK
  25. //password = String.valueOf(i) + String.valueOf(j); OK
  26. password = String.format("%d%d%d%d", i, j, k, l); // OK
  27. passwordIsFound = true;
  28. }
  29. }
  30. }
  31. }
  32. }
  33. }
  34. }
  35. // if(!passwordIsFound){
  36. // System.out.println("No!");
  37. // }else{
  38. // System.out.println("Password: " + password);
  39. // }
  40. System.out.println();
  41. if(password.equals("")){
  42. System.out.println("No!");
  43. }else{
  44. System.out.println("Password: " + password);
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement