Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class numDigitSum
- {
- public static int getSum(int num)
- {
- int sum=0;
- while(num!=0)
- {
- sum=sum+(num%10);
- num=num/10;
- }
- return sum;
- }
- public static void getSmaller(int num)
- {
- boolean check=false;
- int n1=num;
- int checkI;
- int sumOfNum = getSum(n1);
- for(int i=1;i<=n1;i++)
- {
- num--;
- checkI = getSum(num);
- if(checkI==sumOfNum)
- {
- check=true;
- System.out.println("num: "+num);
- }
- }
- if(!check)
- System.out.println("No Match");
- }
- public static void main(String[] args)
- {
- Scanner in =new Scanner(System.in);
- System.out.println("Enter a num");
- int num = in.nextInt();
- getSmaller(num);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement