Sunday, 19 August 2018

how to print java pattern with four triangle


if you solve pattern problem then you grow your program solving ability  in java programming in this post we are providing four triangle  pattern solution  each triangle is opposite direction and make with sticks which is help you how to grow your abilities of Java programming this is important for your programming abilities . Java pattern problems check your programming abilities if you are ICSE board students then you  solve similar problems in your academic exam time we are helping you from pattern solutions.
how to print java pattern with four triangle
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package patterns;

/**
 *
 * @author rajesh kumar shukla
 */
public class pattern2 {
   


    private static void stars(int count) {
        for (int i = 0; i < count; ++i)
            System.out.print("*");
    }

    private static void spaces(int count) {
        for (int i = 0; i < count; ++i)
            System.out.print(" ");
    }

    public static void main(String[] args) {

        int n = 8;

        for (int i = 0; i < n; ++i) {
            stars(i + 1);
            spaces(n - i - 1);
            stars(n - i + 1);
            spaces(2 * i);
            stars(n - i);
            spaces(n - i - 1);
            stars(i + 1);

            System.out.println();
        }

    }
}
output:
run:
*       *****************       *
**      ********  *******      **
***     *******    ******     ***
****    ******      *****    ****
*****   *****        ****   *****
******  ****          ***  ******
******* ***            ** *******
**********              *********

0 comments:

Post a Comment