Thursday, April 19, 2018

Write a program to print square grid pattern !!

// Method-I:
  1. /**
  2.  * 
  3.  * @author ishaan_sharma
  4.  *
  5.  */
  6. public class PrintGridPatternAlgorithm {
  7. public static void main(String[] args) {
  8. printPatten(10);
  9. }

  10. /**
  11.  * n accepts as an input argument to print rows and columns
  12.  * @param n
  13.  */
  14. public static void printPatten(int n) {
  15. for (int i = 0; i < n; i++) {
  16. for (int j = n; j > 0; j--) {
  17. System.out.print("* ");
  18. }
  19. System.out.println();
  20. }
  21. }
  22. }
Output
* * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * * 


// Method-II:
  1. /**
  2.  * 
  3.  * @author ishaan_sharma
  4.  *
  5.  */
  6. public class PrintPatternBy2DArrayAlgorithm {

  7. public static void main(String[] args) {
  8. int a[][] = new int[10][10];
  9. printPattern(a);
  10. }

  11. /**
  12.  * a takes 2D array value
  13.  * @param a
  14.  */
  15. public static void printPattern(int a[][]) {
  16. for (int i = 0; i < 10; i++) {
  17. for (int j = 0; j < 10; j++) {
  18. System.out.print(a[i][j] + " ");
  19. }
  20. System.out.println();
  21. }
  22. }
  23. }
Output: 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 

No comments:

Post a Comment

How to run standalone mock server on local laptop

 Please download the standalone wiremock server from Direct download section at the bottom of the page.  Download and installation Feel fre...