// Method-I:
- /**
- *
- * @author ishaan_sharma
- *
- */
- public class PrintGridPatternAlgorithm {
- public static void main(String[] args) {
- printPatten(10);
- }
- /**
- * n accepts as an input argument to print rows and columns
- * @param n
- */
- public static void printPatten(int n) {
- for (int i = 0; i < n; i++) {
- for (int j = n; j > 0; j--) {
- System.out.print("* ");
- }
- System.out.println();
- }
- }
- }
Output:
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
// Method-II:
- /**
- *
- * @author ishaan_sharma
- *
- */
- public class PrintPatternBy2DArrayAlgorithm {
- public static void main(String[] args) {
- int a[][] = new int[10][10];
- printPattern(a);
- }
- /**
- * a takes 2D array value
- * @param a
- */
- public static void printPattern(int a[][]) {
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- System.out.print(a[i][j] + " ");
- }
- System.out.println();
- }
- }
- }
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