Computer Science, asked by Acakefromdafuture32, 3 months ago

How to print the following Java pattern:--
The pattern will be printed in a centred triangle not in a right angle triangle


1

3 1

5 3 1

7 5 3 1

9 7 5 3 1

Please help me solve this question. I need it for my Computer Assignment

Answers

Answered by atrs7391
0

Solution:

package com.company;  

public class Main {

   public static void main(String[] args) {

       for (int i = 1; i <= 5 ; i++) {

           for (int k=6-i; k>1; k--)

           {

               System.out.print(" ");

           }

           for (int j = 2*i-1; j >=1 ; j-=2) {

               System.out.print(j+" ");

           }

           System.out.println();

       }

   }

}

Output:

      1  

    3 1  

  5 3 1  

 7 5 3 1  

9 7 5 3 1  

Similar questions