I have the following program
public static int doSomething(int num){
if(Math.abs(num) > 9){
return (1 + doSomething( num / 10));
}
else{
return 1;
}
}
public static void main(String[] args){
System.out.println(doSomething(333));
}
This is how I understand it. If the number is 333.
333 / 10
gives me 33
. Since 33 > 9 it runs the recursive loop again giving me 3
.
After 3 it enters the else condition.
I don't understand why it prints 3 as answer.
I am new to java so still trying to understand the basics.
I don't believe the question is a duplicate. My question is much simpler being a beginner to java. Also the question I believe is using javascript not java.