How to put the output of 2 nested loops next to each other?

So I'm currently working on a personal project and I made a program that prints out star patterns. On one of the star patterns I want this input

Figure 1

*        *
**      **
***    ***
****  ****
**********

So I made one method print out this

Figure 2

for(int i = 1; i <= n; i++)
      {
         for(int j = 1; j <= i; j++)
         {
            System.out.print("*" + " ");
         }
         System.out.println("");
      }
*
**
***
****
*****

And another method print out this

Figure 3

for(int i=0; i<n; i++) 
      { 
         for(int j = 2 * (n-i); j >= 0; j--) 
         {           
            System.out.print(" "); 
         } 
         for(int j = 0; j<=i; j++) 
         {       
            System.out.print("* "); 
         }           
         System.out.println();
      } 
    *
   **
  ***
 ****
*****

My question:

How can I put the first method stars next to the other method stars (Refer to Figure 1)

This is what I got so far

public static void printStarsVictory(int n){
      for(int i = 1; i <= n; i++)
      {
         for(int j = 1; j <= i; j++)
         {
            System.out.print("*" + " ");
         }
         System.out.println("");
      }
      for(int i=0; i<n; i++) 
      { 
         for(int j = 2 * (n-i); j >= 0; j--) 
         {           
            System.out.print(" "); 
         } 
         for(int j = 0; j<=i; j++) 
         {       
            System.out.print("* "); 
         }           
         System.out.println();
      } 
   }

This is what is printing so far

*
**
***
****
*****
    *
   **
  ***
 ****
*****

Any idea how to solve this? Thank you in advance!



Read more here: https://stackoverflow.com/questions/64897443/how-to-put-the-output-of-2-nested-loops-next-to-each-other

Content Attribution

This content was originally published by Joseph Attia at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: