Hi there,
Where is my mistake? Is my code right?
package com.codegym.task.task30.task3010;
/*
Smallest possible radix
*/
import java.math.BigInteger;
public class Solution
{
public static void main(String[] args)
{
//write your code here
// args = new String[]{" EZ"};
if (isValidString(args[0]))
{
System.out.println(getMinimumRadix(args[0]));
}
else {
System.out.println("Invalid");
}
}
// Checks if all chars in args[0] are letters o number
private static boolean isValidString(String str)
{
boolean isValid = false;
char[] ch = str.toCharArray();
for(char c : ch){
isValid = Character.isLetterOrDigit(c);
if(!isValid)
{
break;
}
}
return isValid;
}
private static String getMinimumRadix(String str)
{
final int LOWER_RADIX = 2;
final int UPPER_RADIX = 36;
for(int radix = LOWER_RADIX; radix <= UPPER_RADIX; radix++)
{
try
{
BigInteger number = new BigInteger(str, radix);
return String.valueOf(radix);
}
catch(Exception e)
{
}
}
return null;
}
}