• + 0 comments

    here is the first version, even main() has been corrected :

    public class Solution {
    
        /*
         * Complete the xorMatrix function below.
         */
        static int[] xorMatrix(long m, int[] first_row) {
             
             int n = first_row.length;
             int save0;
             
             for( long i=1; i<m; i++){
                save0 = first_row[0];
                for( int j=0; j < n-1; j++){
                   first_row[j] = first_row[j] ^ first_row[j+1];
                }            
                first_row[n-1] = first_row[n-1] ^ save0;
             }
             
             return first_row;
             
    
        }
    
        private static final Scanner scanner = new Scanner(System.in);
    
        public static void main(String[] args) throws IOException {
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
    
            String[] nm = scanner.nextLine().split(" ");
    
            int n = Integer.parseInt(nm[0].trim());
    
            long m = Long.parseLong(nm[1].trim());
    
            int[] first_row = new int[n];
    
            String[] first_rowItems = scanner.nextLine().split(" ");
    
            for (int first_rowItr = 0; first_rowItr < n; first_rowItr++) {
                int first_rowItem = Integer.parseInt(first_rowItems[first_rowItr].trim());
                first_row[first_rowItr] = first_rowItem;
            }
    
            int[] result = xorMatrix(m, first_row);
    
            for (int resultItr = 0; resultItr < result.length; resultItr++) {
                bufferedWriter.write(String.valueOf(result[resultItr]));
    
                if (resultItr != result.length - 1) {
                    bufferedWriter.write(" ");
                }
            }
    
            bufferedWriter.newLine();
    
            bufferedWriter.close();
        }
    }