Пробовал тесты с комментариев, вроде все верно выводит. Может кто подскажет, что не то. Закончились мысли. То ли логику я не так продумал, то ли валидатор только через BigInteger принимает, то ли где-то ошибку допустил.
package com.javarush.task.task30.task3010;
import java.nio.charset.StandardCharsets;
import java.util.regex.Pattern;
/*
Минимальное допустимое основание системы счисления
*/
public class Solution {
public static void main(String[] args) {
String enter = null;
try {
enter = args[0]; //строка, которая содержит последовательность символов (Все символы в строке имеют коды в таблице ASCII от 32 до 127 включительно)
} catch (Exception e) {}
if (enter == null) return;
byte[] listByte = enter.getBytes(StandardCharsets.UTF_8);
byte maxByte = listByte[0];
for (byte b : listByte) {
if (!isCorrect(b)) return;
if (b > maxByte) {
maxByte = checkMaxByte(b, maxByte);
}
}
System.out.println(getNumberSystem(maxByte));
}
private static byte checkMaxByte(byte b, byte maxByte) {
if (b > 96) {
b -= 32;
if (b > maxByte) return b;
}
return b;
}
private static boolean isCorrect(byte b) {
if (b <= 47 || b >= 123) {
System.out.println("incorrect");
return false;
}
if ((b >= 58 && b <= 64) || (b >= 91 && b <= 96)) {
System.out.println("incorrect");
return false;
}
return true;
}
// if return 0 - it's exception
private static int getNumberSystem(byte b) {
switch (b) {
case (48):
case (49):
return 2;
case (50):
return 3;
case (51):
return 4;
case (52):
return 5;
case (53):
return 6;
case (54):
return 7;
case (55):
return 8;
case (56):
return 9;
case (47):
return 10;
case (65):
return 11;
case (66):
return 12;
case (67):
return 13;
case (68):
return 14;
case (69):
return 15;
case (70):
return 16;
case (71):
return 17;
case (72):
return 18;
case (73):
return 19;
case (74):
return 20;
case (75):
return 21;
case (76):
return 22;
case (77):
return 23;
case (78):
return 24;
case (79):
return 25;
case (80):
return 26;
case (81):
return 27;
case (82):
return 28;
case (83):
return 29;
case (84):
return 30;
case (85):
return 31;
case (86):
return 32;
case (87):
return 33;
case (88):
return 34;
case (89):
return 35;
case (90):
return 36;
}
return 0;
}
}