Such a situation - inside the method I call System.out.println (""); on the screen displays 2-3 times the same thing. Before calling this method, everything is fine, and after, too.

What could be so confused that the output on the screen has become multiple? The output to the screen inside the method is the first line. Just a test phrase like "hello" and then go the calculations.

So this hello is written 2 times. And all subsequent conclusions on the screen inside the method go 2-3 times.

Before this method I worked with adding objects to the list and removing them by assigning null;

Calling the calculatesMainFunctionA method

 NrezultTask2TypeIntervalSet.calculatesMainFunctionA(rezultTask1TypeInterval,0, numberX); 

The calculatesMainFunctionA() method:

  public void calculatesMainFunctionA(Interval variableInterval, int positionInIntersectionSet, double ourInputX){ System.out.println("Привет"); int i = this.intervalSet.size(); boolean oneXorTwoX = true; if (ourInputX < this.intervalSet.get(positionInIntersectionSet).getFrom()){ variableInterval.putFrom(this.intervalSet.get(positionInIntersectionSet).getFrom()); oneXorTwoX=true; } if (ourInputX >=this.intervalSet.get(positionInIntersectionSet).getFrom()){//x>=x1 if (ourInputX<=this.intervalSet.get(positionInIntersectionSet).getTo()){//x<=x2 variableInterval.putFrom(ourInputX); oneXorTwoX=true; } else{ if (positionInIntersectionSet+1==i) { variableInterval.putFrom(this.intervalSet.get(positionInIntersectionSet).getTo());//return x2 oneXorTwoX=true; } else { if (ourInputX>=this.intervalSet.get(positionInIntersectionSet+1).getFrom()){//x>=x1n positionInIntersectionSet++; calculatesMainFunctionA(variableInterval,positionInIntersectionSet,ourInputX); } else { if ((ourInputX-this.intervalSet.get(positionInIntersectionSet).getTo())==(this.intervalSet.get(positionInIntersectionSet+1).getFrom()-ourInputX)){//f=f1 variableInterval.putTo(this.intervalSet.get(positionInIntersectionSet+1).getFrom()); variableInterval.putFrom(this.intervalSet.get(positionInIntersectionSet).getTo()); oneXorTwoX=false; } if ((ourInputX-this.intervalSet.get(positionInIntersectionSet).getTo())>(this.intervalSet.get(positionInIntersectionSet+1).getFrom()-ourInputX)){//f>f1 variableInterval.putFrom(this.intervalSet.get(positionInIntersectionSet+1).getFrom()); oneXorTwoX=true; } else{ variableInterval.putFrom(this.intervalSet.get(positionInIntersectionSet).getTo()); oneXorTwoX=true; } } } } } if (oneXorTwoX==true){ System.out.print("Для заданного числа X результатом будет такое число: "); System.out.print(variableInterval.toString(variableInterval.getFrom())); System.out.println(" ;-)"); } else { System.out.print("Для заданного числа X результатом будет 2 числа: "); System.out.print(variableInterval.toString(variableInterval.getFrom())); System.out.println(" и "+variableInterval.toString(variableInterval.getTo())); } } 

the screen will be

 Привет Привет Ответом будет 5 Ответом будет 5 
  • 3
    Show your code - Barmaley
  • one
    your method is called 2-3 times - Andrew Bystrov
  • If I had been called about 2 times, it would be on the screen like this - Hello Answer Hello Answer And I have: Hello Hello Answer Answer - batqr
  • one
    it means you, where // the calculations go, the same method is called, since Recruitment - Andrew Bystrov
  • one
    give all the code, well, as if all IDEs have a debug mode - Dejsving

1 answer 1

Here is this part of the code:

 if (ourInputX>=this.intervalSet.get(positionInIntersectionSet+1).getFrom()){//x>=x1n positionInIntersectionSet++; calculatesMainFunctionA(variableInterval,positionInIntersectionSet,ourInputX); } 

You call the method again, and accordingly you receive Hi again! and again the answer.