Не понимаю, почему решение не проходит валидатор. На мой взгляд метод работает верно:
private boolean compressRow(int[] row){
int pivotX;
boolean changesMade = false;
for (int i = 0; i < row.length; i++) {
if(row[i]==0){
pivotX = i; //нашли 0
for(int findValue = pivotX;findValue<row.length;findValue++){ // ищем 2 или 4
if(row[findValue] == 2 || row[findValue] == 4){ // если нашли 2 или 4
row[pivotX] = row[findValue];
row[findValue] = 0;
pivotX++;
changesMade = true;
}
}
}
}
return changesMade;
}
package com.javarush.games.game2048;
public class test {
public static void main(String[] args) {
int[]row = {2,4,0,0};
int pivotX = 0;
boolean changesMade = false;
for (int i = 0; i < row.length; i++) {
if(row[i]==0){
pivotX = i; //нашли 0
for(int findValue = pivotX;findValue<row.length;findValue++){ // ищем 2 или 4
if(row[findValue] == 2 || row[findValue] == 4){ // если нашли 2 или 4
row[pivotX] = row[findValue];
row[findValue] = 0;
pivotX++;
changesMade = true;
}
}
}
}
for (int x:row) {
System.out.println(x);
}
System.out.println(changesMade);
}
}