Print matrix in waveform in java.
class Ved
{
public static void main(String[] args)
{
int[][] arr={{1,2,3},{4,5,6},{7,8,9}};
int n=arr.length;
System.out.println("elements according waveform =");
// logic of program
for(int i=0; i<n; i++){
if(i%2==0){
for(int j=0; j<n; j++){
System.out.print(arr[i][j]+" ");
}
}
else
{
for(int j=n-1; j>=0; j--){
System.out.print(arr[i][j]+" ");
}
}
}
}
}
■》 Output->
elements according waveform =
1 2 3 6 5 4 7 8 9
Comments
Post a Comment