The move () method is given - initially it is empty, I fill it myself, which moves the car 1 meter forward or backward. When moving forward, it returns true, and when moving back, it returns false. The car itself decides where it goes in when you call the move method. The task is to move the car 10 meters forward from the initial position of the car. The move () method, according to the task, cannot be touched; you can only call it and use the result of the execution. Sketches:

package pckgCar; public class Car { public static int mCar = 0; //пер. для генерации 0 или 1 public static int mCarLen = 0; //пер. для подсчета метров public static boolean A; //пер. для возврата true||false в методе public static void main(String[] args) { //главная ф-ция move(); //вызываем move() } public static boolean move(){ //возвращает true||false moving(); //вызов метода moving(); if(mCarLen==10){ //если набралось 10 метров, то A = true; //приехали System.out.println("Приехали."); } return A; //возврат значения } public static void moving(){ //генерация 0 или 1, для вызова в мув, мув же не трогаем do //делаем: { mCar = (int) (mCar + (Math.random() * ((-1 - 0)+1))); //генерацию 0 или 1 if(mCar==1){ //если 1, то mCarLen++; //увеличичваем счетчик метров на 1, } }while(mCarLen < 11); //пока не наберем 10 } } 
  • And the question is what? or need to come up with a question? But moving is strange. - KoVadim
  • @KoVadim well, it does not work, does not even go into if, where the output is Alexander Vasilchuk
  • (Math.random() * ((-1 - 0)+1)) there will always be 0 here. Brackets more carefully put. - KoVadim
  • @KoVadim there is a minus extra, I put, checked, I have written ... ((1 - 0) +1))), it generates correctly - either 0 or 1, the problem is somewhere in the cycles, maybe? - Alexander Vasilchuk
  • Please write how the code is called / tested and what exactly is going wrong, as expected. It is best to create a MSVP - default locale

0