Name: Anonymous 2011-01-23 18:05
Hey /prog/, I haven't been here in a while and I was wondering if you guys could offer some basic programming help.
I'm writing a program that parses integers and returns the word, i.e. 100 yeilds "one hundred." Obviously I'm not going to post all of the code. I'm only having trouble implementing this one method.
//Return any single digit of the instance variable
//Parameter index gives the position of the required digit
//index 0 indicates the least significant digit
//Example: 7046
//Digit-0 = 6, Digit-1 = 4, Digit-2 = 0, Digit-3 = 7
//All higher-indexed (4, 5, 6, ...) digits are 0
//A RuntimeException is thrown if parameter index < 0
//
public int getDigit(int index)
{
String numStr = Integer.toString(this.number);
if(index < 0)
throw new RuntimeException("Invalid index");
else //wtf do I do?
}//end of getDigit
this.number is a private class instance variable
What throws me off is that the indexes are backwards.
tl;dr noob needs java help
I'm writing a program that parses integers and returns the word, i.e. 100 yeilds "one hundred." Obviously I'm not going to post all of the code. I'm only having trouble implementing this one method.
//Return any single digit of the instance variable
//Parameter index gives the position of the required digit
//index 0 indicates the least significant digit
//Example: 7046
//Digit-0 = 6, Digit-1 = 4, Digit-2 = 0, Digit-3 = 7
//All higher-indexed (4, 5, 6, ...) digits are 0
//A RuntimeException is thrown if parameter index < 0
//
public int getDigit(int index)
{
String numStr = Integer.toString(this.number);
if(index < 0)
throw new RuntimeException("Invalid index");
else //wtf do I do?
}//end of getDigit
this.number is a private class instance variable
What throws me off is that the indexes are backwards.
tl;dr noob needs java help