Java keep printing a new line in my recursive method
Posted
by
Abra Grace Libretto White
on Stack Overflow
See other posts from Stack Overflow
or by Abra Grace Libretto White
Published on 2012-10-14T03:32:44Z
Indexed on
2012/10/14
3:36 UTC
Read the original article
Hit count: 139
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?
© Stack Overflow or respective owner