Java keep printing a new line in my recursive method
- by Abra Grace Libretto White
I am trying to write a recursive method to print n number of asteriks in a line and create a new line at the end.
So, TriangleOps.line(5);
would print
*****
This is the code I wrote:
public static void line (int n){
if(n>0){
System.out.println("*");
line(n-1);
}}
instead it prints
*
*
*
*
*
with a lot of space at the end. Can anyone tell me how to remove the line breaks?