forked from panditakshay402/Hacktoberfest2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |