jw44250
BAN USERint len = cars.length-1;
char [] updated = new char[cars.length];
int count = 0;
int carPosition = 0;
for(int i = 0; i < cars.length; i++) {
char movedCar = 0;
updated[i] = cars[i];
if(cars[i] == '0') {
if(count == 0) {
// Find Empty spat moved to End move
// moved End Empty spat
movedCar = cars[i];
cars[i] = cars[len];
carPosition = i;
cars[len] = movedCar;
count++;
}else {
while(count == carPosition) {
}
char currentCar = cars[carPosition];
movedCar = cars[carPosition-2];
cars[carPosition] = movedCar;
cars[carPosition-2] = currentCar;
currentCar = cars[carPosition-2];
movedCar = cars[carPosition-1];
cars[carPosition-1] = currentCar;
cars[carPosition-2] = movedCar;
currentCar = cars[carPosition-2];
currentCar = cars[carPosition-4] ;
movedCar = cars[carPosition-2];
cars[carPosition-2]= currentCar;
cars[carPosition-4]= movedCar;
movedCar = cars[0];
currentCar = cars[carPosition-3] ;
cars[0]= currentCar;
cars[carPosition-3] = movedCar;
}
}
}
for (int j = 0; j < cars.length; j++) {
System.out.print(cars[j] + " ");
}
int len = cars.length-1;
- jw44250 February 23, 2019char [] updated = new char[cars.length];
int count = 0;
int carPosition = 0;
for(int i = 0; i < cars.length; i++) {
char movedCar = 0;
updated[i] = cars[i];
if(cars[i] == '0') {
if(count == 0) {
// Find Empty spat moved to End move
// moved End Empty spat
movedCar = cars[i];
cars[i] = cars[len];
carPosition = i;
cars[len] = movedCar;
count++;
}else {
while(count == carPosition) {
}
char currentCar = cars[carPosition];
movedCar = cars[carPosition-2];
cars[carPosition] = movedCar;
cars[carPosition-2] = currentCar;
currentCar = cars[carPosition-2];
movedCar = cars[carPosition-1];
cars[carPosition-1] = currentCar;
cars[carPosition-2] = movedCar;
currentCar = cars[carPosition-2];
currentCar = cars[carPosition-4] ;
movedCar = cars[carPosition-2];
cars[carPosition-2]= currentCar;
cars[carPosition-4]= movedCar;
movedCar = cars[0];
currentCar = cars[carPosition-3] ;
cars[0]= currentCar;
cars[carPosition-3] = movedCar;
}
}
for (int j = 0; j < cars.length; j++) {
System.out.print(cars[j] + " ");