String[] tokens = s.split(' ');
for(int i = 0; i < (tokens.length) - 1; ++i)
{
if(isDigit(tokens[i]))
{
// Two numbers cannot be together without an operator.
if(isDigit(tokens[i + 1]))
{
check = 1;
break;
}
if((tokens[i + 1] == '(') )
{
check = 1;
break;
}
}
}
s is the string i’m splitting. after splitting i want to check whether each split part is a digit. i m not able to use isDigit because it can only be used on characters and here the split part is String.
NOTE: i m writing a program for a calculator. if i use toCharArray() the more than one digit numbers will be split. eg. 23 will become 2 and 3 seperately.
1 Answer