Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1
- public class Programmiertest3 {
- 2
- private static int nDigits(int n) {
- 3
- int count = 0;
- 4
- while(n > 0) {
- 5
- n /= 10;
- 6
- count++;
- 7
- }
- 8
- return count;
- 9
- }
- 10
- 11
- private static int mSDigit(int n) {
- 12
- int digitNumber = nDigits(n);
- 13
- int max = 0;
- 14
- for (int i = 0; i < digitNumber; i++) {
- 15
- max = max > (n % 10) ? max : n % 10;
- 16
- n /= 10;
- 17
- }
- 18
- return max;
- 19
- }
- 20
- 21
- private static String substringA(String s) {
- 22
- if(s.length() <= 1) {
- 23
- return s;
- 24
- }
- 25
- String temp = substringA(s.substring(1));
- 26
- if (temp.charAt(0) == 'A') {
- 27
- return temp;
- 28
- }
- 29
- return s;
- 30
- }
- 31
- 32
- public static void main(String[] args) {
- 33
- String text1 = "Just AA Test!";
- 34
- String text2 = "Servus!";
- 35
- 36
- System.out.println(nDigits(70123));
- 37
- System.out.println(mSDigit(70123));
- 38
- System.out.println(nDigits(5));
- 39
- System.out.println(mSDigit(5));
- 40
- System.out.println(substringA(text1));
- 41
- System.out.println(substringA(text1 + text1));
- 42
- System.out.println(substringA(text2));
- 43
- System.out.println(substringA(text1 + text2));
- 44
- }
- 45
- }
- 46
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement