hi :)
This program requires me to read user input from the commandline (a int and a string) and use recursion to print out the the first letter of the string x times based on the int user input:
I have this so far, but it seems print out just one instance...it doesn't seem to be looping up to the for statement
public class test
{
/*******************************************************************************
* Initializes program
* @ param commandlineArguments
********************************************************************************/
public static void main(String[] commandlineArguments)
{
if (commandlineArguments.length == 0) {
System.out.print("Error: You must enter at least 1 commandline argument ");
}
else
{
Integer number = new Integer(0); //initialize number
String word = commandlineArguments[1];
try // check to verify if input is an integer
{
number = Integer.parseInt(commandlineArguments[0]);
}
catch (NumberFormatException exception) // NumberFormatException
{
System.out.print(exception);
System.out.println(" is not an integer");
System.exit(1); // end program
}
String outputString; // declares String
Integer outputInt; // declares Integer
outputString = printString(number, word); // calls printStars method
System.out.println( outputString ); //prints printStars method
}
}
public static String letter( int start, String oneWord )
{
if( start == 0 ) // if start = 0, then result is 0.
{
return "0";
}
else
{
oneWord = oneWord.substring(0,1);
for (int i = 0; i < start; i++)
{
oneWord = oneWord;
}
return oneWord;
}
}
Thank you in advance for you help!! :)