Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class demo {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int n = Integer.parseInt(scan.nextLine());
- int count = 0;
- String password = "";
- boolean passwordIsFound = false;
- for (int i = 1; i <= 9; i++) {
- for (int j = 1; j <= 9; j++) {
- for (int k = 1; k <= 9; k++) {
- for (int l = 1; l <= 9; l++) {
- if (i < j && k > l) {
- if (i * j + k * l == n) {
- count++;
- System.out.printf("%d%d%d%d ", i, j, k, l);
- if (count == 4) {
- // password = i + "" + j + "" + k + "" + l + ""; OK
- //password = "i" + "j" + "k" + "l"; Not OK
- //password = String.valueOf(i) + String.valueOf(j); OK
- password = String.format("%d%d%d%d", i, j, k, l); // OK
- passwordIsFound = true;
- }
- }
- }
- }
- }
- }
- }
- // if(!passwordIsFound){
- // System.out.println("No!");
- // }else{
- // System.out.println("Password: " + password);
- // }
- System.out.println();
- if(password.equals("")){
- System.out.println("No!");
- }else{
- System.out.println("Password: " + password);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement