takes two numbers m and n on the command line and writes out a triangle pattern of asterisks
public class Triangle {
public static void main(String[] args) {
int a=0;
int b=0;
if(args.length!=0){
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
}
printFirstHalf(a,b);
printSecondHalf(a,b);
}
public static void printFirstHalf(int m, int n){
if(m==0){
return;
}
//recursive step
for(int i=m; i<=n; i++){
System.out.print("*");
}
System.out.println();
printFirstHalf(m-1,n);
}
public static void printSecondHalf(int m, int n){
if(m==0){
return;
}
printSecondHalf(m-1,n);
//recursive step
for(int i=m; i<=n; i++){
System.out.print("*");
}
System.out.println();
}
}
If 3 and 7 are sent in it should print:
***
****
*****
******
*******
*******
******
*****
****
***
Right now it prints out:
*****
******
*******
*******
******
*****
I know I am close but for some reason I am majorly stuck.