-1

Why does my code output vertically instead of horizontally? I'm new to programming and I just need to to output the basic

I've look around for this problem. I copied my teachers code just to see if its my code but still doesn't work. I am using IntelliJ IDEA CE

public static void main(String[] args) {
    for (int i = 1; i < 10; i++) {
        for (int j = 0; j < 5; j++) {
            System.out.println("*");
        }
        System.out.println("");
    }
}
  • Are you able to show us an example of the output that you require? This line here: System.out.println(""); Gives you a new line after a * which is why you are getting vertical. – elarcoiris Apr 26 '19 at 02:38

2 Answers2

2

remove "ln" from "println". Use System.out.print("*");

"ln" means Next Line, so if you want print in the same line use "print" only.

0

That is because you are using System.out.println("*"); instead of System.out.print("*");.

When you use println it append \n\r after you string, so it make the starts show in vertical.

Hope this helped :)

Bastida
  • 105
  • 1
  • 9