Sunday, July 16, 2017

Write a Java program that will print the pattern as shown below.

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


/**
 * Created by Jo on 7/10/2017.
 * For more exercises and lessons, visit http://shegertech.blogspot.com/
 * Chapter 5, Exercise 4
 */

public class Q4Solution {
    public static void main(String[] args) {
        int i=0;
        int j=0;

        for(i=1;i<=9;i=i+2){
            for(j=1;j<=i;++j)
                System.out.print("*");

            System.out.print("\n");

        }
        for(i=9;i>=1;i=i-2){
            for(j=i;j>=1;--j)
                System.out.print("*");

            System.out.print("\n");


        }

        System.out.print("\n");

    }
}

Share: