So is it okay if I use the library function that converts
the string to char array?
>> Yes.
>> So charArray, so I believe there's
a levering method just converts a string to charArray.
>> It's actually a method on the string objects itself.
>> Okay, so it's just input.toCharArray,
and is it possible for the input to be empty or
not numerical should I consider that?
>> You should definitely consider that case.
>> All right, so in this case if my array's or
my string's empty, I would throw an exception to
tell the user that they've entered an illegal argument.
So put not string and so
then they can enter different.
Or is it okay to just like return zero?
>> What do you think?
Do you think I should throw in exception or throw in zero?
Which one's better?
>> Well, if we return zero in this case we might not know if what
happens if the user actually enters zero.
We could return a negative number but then we have to worry about it later,
what to do when this method does return a negative number.
So I think throwing out exceptions is the best case here.
>> Sure. >> Okay, so I'm going to throw
a new illegalArgumentException
[BLANK AUDIO] and
I'm going to say Must be
a valid number string and
then I can check later if my
digits are indeed numerical.
>> All right, so you said this, so I know you know.
But I think you need to throw that exception when input is empty,
not when it's not empty.
>> Yes, so this should be equals, and actually I shouldn't be using
equals at all, because it's a string, and string is an object.
So in this case, I should be using equals to actually check the equality.
And I want to make sure that the input is not null,
because I assume that it could be null as well.
So if input is null, or that its empty,
that would throw an IllegalArgumentException.
And I think I'm ready to loop through the charArray.
So this is just the for loop construct.
And getting the length of the charArray and
length is just a field inside the array.
And then, inside this for
loop I'm going to loop through each digits and
then added to an integer value [BLANK AUDIO] and
this is what I will be returning later so
I can just do some simple math by multiplying
ten to increase the number of places and
I'll add in the digits.
Is it okay if I use the character method to convert the character to digit?
>> Sure.
>> Okay, so, Character.toDigit(charArr[I] and
then I'll return value here, and
then let me just walk through going
back to my example to see this actually works
[MUSIC]