KnowledgeBoat Logo

Java Pattern Programs

Write a program in Java to display the following pattern:

    1
   35
  579
 7913
91357

Java

Java Nested for Loops

ICSE

3 Likes

Answer

public class KboatPattern
{
   public static void main(String args[]) {
       for (int i = 1, x = 1; i <= 9; i = i+2, x++) {
           for (int z = 5; z > x; z--) {
               System.out.print(" ");
           }
           for (int j = i, y = 1; y <= x; j = j+2, y++) {
               if (j > 9)
                   j = 1;
               System.out.print(j);
               
           }
           System.out.println();
       }
   }
}

Output

BlueJ output of Write a program in Java to display the following pattern: 1 35 579 7913 91357

Answered By

3 Likes