Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Test {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int sum = Integer.parseInt(input.nextLine());
- int diff = Integer.parseInt(input.nextLine());
- boolean dontHaveSum = true;
- for (int i = 5; i <= 9; i++) {
- for (int j = 5; j <= 9; j++) {
- for (int j2 = 5; j2 <= 9; j2++) {
- String ghi = "" + i + j + j2;
- int ghiInt = Integer.parseInt(ghi);
- int defInt = ghiInt - diff;
- int abcInt = ghiInt - (2 * diff);
- int f = defInt % 10;
- defInt /= 10;
- int e = defInt % 10;
- defInt /=10;
- int d = defInt;
- int c = abcInt % 10;
- abcInt /= 10;
- int b = abcInt % 10;
- abcInt /=10;
- int a = abcInt;
- int digitsSum = i + j + j2 + f + e + d + c + b + a;
- if (digitsSum == sum && f >= 5 && f <= 9 && e >= 5 && e <= 9 && d >= 5 && d <= 9
- && a >= 5 && a <= 9 && b >= 5 && b <= 9 && c >= 5 && c <= 9) {
- System.out.println(""+a + b + c + d + e + f + i + j + j2);
- dontHaveSum=false;
- }
- }
- }
- }
- if (dontHaveSum) {
- System.out.println("No");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement