Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. public static void main(){
  2. isDigitIncreasing(7);
  3. isDigitIncreasing(36);
  4. isDigitIncreasing(984);
  5. isDigitIncreasing(7404);
  6. isDigitIncreasing(37);
  7. }
  8.  
  9. static int isDigitIncreasing(int n){
  10. int numberDigits = 0;
  11. int tempNum = n;
  12. while(tempNum>0){
  13. tempNum /= 10;
  14. numberDigits++;
  15. }
  16. if (numberDigits == 0){
  17. numberDigits = 1;
  18. }
  19. for (int i = 1;i<10;i++){
  20. int sum = 0;
  21. for (int j = 1;j<numberDigits+1;j++){
  22. if (j==1){
  23. sum += i;
  24. }else{
  25. int x = 1;
  26. for (int k = 1;k<j;k++){
  27. x += Math.pow(10, k);
  28. }
  29. sum += i*x;
  30. }
  31. }
  32. if (sum == n){
  33. return 1;
  34. }
  35. }
  36.  
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement