import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int [][]arr=new int[n][m];
for(int i=0;i<arr.length;i++) {
for(int j=0;j<arr.length;j++) {
arr[i][j]=sc.nextInt();
}
}
printrowwise(arr);
sc.close();
}
public static void printrowwise(int [][]arr) {
for(int i=0;i<arr.length;i++) {
if(i%2==0) {
for(int j=0;j<arr[i].length;j++) {
System.out.print(arr[i][j]+", “);
}
}
else {
for(int j=arr[i].length-1;j>=0;j–) {
System.out.print(arr[i][j]+”, ");
}
}
}
System.out.println(“END”);
}
}
Still getting wrong test cases,please you try this code and check
You have an error while taking the matrix input.
It should be j<arr[i].length
Here’s your updated code.
Share your code using the online IDE from next time onwards.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.