Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. 1
  2.  
  3. public class Programmiertest3 {
  4. 2
  5.  
  6. private static int nDigits(int n) {
  7. 3
  8.  
  9. int count = 0;
  10. 4
  11.  
  12. while(n > 0) {
  13. 5
  14.  
  15. n /= 10;
  16. 6
  17.  
  18. count++;
  19. 7
  20.  
  21. }
  22. 8
  23.  
  24. return count;
  25. 9
  26.  
  27. }
  28. 10
  29.  
  30. 11
  31.  
  32. private static int mSDigit(int n) {
  33. 12
  34.  
  35. int digitNumber = nDigits(n);
  36. 13
  37.  
  38. int max = 0;
  39. 14
  40.  
  41. for (int i = 0; i < digitNumber; i++) {
  42. 15
  43.  
  44. max = max > (n % 10) ? max : n % 10;
  45. 16
  46.  
  47. n /= 10;
  48. 17
  49.  
  50. }
  51. 18
  52.  
  53. return max;
  54. 19
  55.  
  56. }
  57. 20
  58.  
  59. 21
  60.  
  61. private static String substringA(String s) {
  62. 22
  63.  
  64. if(s.length() <= 1) {
  65. 23
  66.  
  67. return s;
  68. 24
  69.  
  70. }
  71. 25
  72.  
  73. String temp = substringA(s.substring(1));
  74. 26
  75.  
  76. if (temp.charAt(0) == 'A') {
  77. 27
  78.  
  79. return temp;
  80. 28
  81.  
  82. }
  83. 29
  84.  
  85. return s;
  86. 30
  87.  
  88. }
  89. 31
  90.  
  91. 32
  92.  
  93. public static void main(String[] args) {
  94. 33
  95.  
  96. String text1 = "Just AA Test!";
  97. 34
  98.  
  99. String text2 = "Servus!";
  100. 35
  101.  
  102. 36
  103.  
  104. System.out.println(nDigits(70123));
  105. 37
  106.  
  107. System.out.println(mSDigit(70123));
  108. 38
  109.  
  110. System.out.println(nDigits(5));
  111. 39
  112.  
  113. System.out.println(mSDigit(5));
  114. 40
  115.  
  116. System.out.println(substringA(text1));
  117. 41
  118.  
  119. System.out.println(substringA(text1 + text1));
  120. 42
  121.  
  122. System.out.println(substringA(text2));
  123. 43
  124.  
  125. System.out.println(substringA(text1 + text2));
  126. 44
  127.  
  128. }
  129. 45
  130.  
  131. }
  132. 46
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement