Skip to content

Commit

Permalink
Create WavePrintMatrixProgram.java
Browse files Browse the repository at this point in the history
This is the program for the "Wave Print Matrix Program" addressed in the Issue Number 222. I believe this is exactly what was asked to do, so kindly merge it into the repo. This is the Java Version of the same, i will be making and requesting for the C++ version too, so kindly see that too in PRs.

Link to the issue : panditakshay402#222
  • Loading branch information
mreshank committed Oct 29, 2023
1 parent 15af29a commit 84a8e51
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions JAVA/WavePrintMatrixProgram.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//Wave Print Matrix Program - Mr. Eshank Tyagi
import java.util.*;
class WavePrintMatrixProgram
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

System.out.print("\nEnter the number of rows : ");
int r = sc.nextInt();

System.out.print("\nEnter the number of columns : ");
int c = sc.nextInt();

int[][] arr = new int[r][c];

System.out.println("\nEnter the elements of the matrix :-");

for(int i = 0; i < r; i++)
{
for(int j = 0; j < c; j++)
{
arr[i][j] = sc.nextInt();
}
}

System.out.println("The matrix is :-");

for(int i = 0; i < r; i++)
{
for(int j = 0; j < c; j++)
System.out.print(arr[i][j] + " ");

System.out.println();
}

System.out.println("The wave print of the matrix is :-");

for(int i = 0; i < c; i++)
{
if(i % 2 == 0)
{
for(int j = 0; j < r; j++)
System.out.print(arr[j][i] + " ");
}
else
{
for(int j = r - 1; j >= 0; j--)
System.out.print(arr[j][i] + " ");
}
}
sc.close();
}
}

0 comments on commit 84a8e51

Please sign in to comment.