Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a method that accepts the input of how many lines theuser wants and then p

ID: 3612706 • Letter: W

Question

Write a method that accepts the input of how many lines theuser wants and then prints the same number of characters to theline as the line number. Once the number of characters is the sameas the user input for the number of lines you then decrement backdown to zero. For example: the call printStars(1,4) would result in * ** *** **** *** ** * Write a method that accepts the input of how many lines theuser wants and then prints the same number of characters to theline as the line number. Once the number of characters is the sameas the user input for the number of lines you then decrement backdown to zero. For example: the call printStars(1,4) would result in * ** *** **** *** ** *

Explanation / Answer


import java.io.*;
public class drawtriangle
{public static void main(String[] args)
{
printstars(1,4);
}
public static void printstars(int row,int max)
{int i;
if(max==0)
   return;
if(row<max)
    {for(i=0;i<row;i++)
     System.out.print("*");
   System.out.println();
     printstars(row+1,max);
}
else
    {for(i=0;i<max;i++)
     System.out.print("*");
   System.out.println();
     printstars(row,max-1);
}

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote