Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- /**
- * Created by kolinsol on 5/5/17.
- */
- public class Runner {
- public static void main(String[] args) {
- Runner runner = new Runner();
- Scanner input = new Scanner(System.in);
- System.out.println("Введите сумму цифр");
- Integer a = input.nextInt();
- System.out.println("Введите количество цифр");
- Integer n = input.nextInt();
- System.out.println(runner.findResult(a, n));
- }
- private Integer getDigitSum(Integer value) {
- Integer tempSum = 0;
- while(value > 0) {
- tempSum += (value % 10);
- value /= 10;
- }
- return tempSum;
- }
- private Integer getDigitCount(Integer value) {
- Integer tempCount = 0;
- while(value > 0) {
- tempCount++;
- value /= 10;
- }
- return tempCount;
- }
- private Integer findResult(Integer sum, Integer lengthLimit) {
- Boolean isBigger = false;
- Integer tempMaxValue = 0;
- for (int i = 0; !isBigger; i++) {
- if (getDigitCount(i) > lengthLimit) {
- isBigger = true;
- } else if (getDigitSum(i) == sum) {
- tempMaxValue = i;
- }
- }
- return tempMaxValue;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement