0

Why this problem print 95?

public class First { public static int CBSE(int x){ if(x < 100) x=CBSE(x + 10); return (x-1); } public static void main (String[] args){ System.out.print(First.CBSE(60)); } }

3rd Jun 2020, 2:49 AM
Juan Debenedetti
Juan Debenedetti - avatar
2 odpowiedzi
+ 3
The method is called recursively until x has a value greater or equal 100. This takes 5 iterations (60>70>80>90>100). After this is reached, for each iteration there is subtracted 1. 100-1-1-1-1-1 = 95
3rd Jun 2020, 3:00 AM
Sandra Meyer
Sandra Meyer - avatar