Sunday, 19 August 2018

how print square pattern in java programming


hello dear student I am providing pattern solution of Java programming you can use this solution in your exam and find find your goal this post we are providing square  pattern solution square print with stick.
how print square pattern in java programming
/*
 * 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 pattern3 {
   


    public static void main(String[] args) {
        int number = 7;

        for (int i = 0; i < number; i++) {
            if (i == 0 || i == 6) {
                for (int j = 0; j < number; j++) {
                    System.out.print("*");
                }
                System.out.println();
            }
            if (i >= 1 && i <= 5) {
                for (int j = 0; j < number; j++) {
                    if (j == 0 || j == 6) {
                        System.out.print("*");
                    } else if (j >= 1 && j <= 5) {
                        System.out.print(" ");
                    }
                }
                System.out.println();
            }
        }
    }
}
output:
run:
*******
*     *
*     *
*     *
*     *
*     *
*******

0 comments:

Post a Comment