Just wrote simple java code to print 1 - 100 using recursive method.
Below is the code snippet
public class Test
{
public static void main(String[] a)
{
printNumber(0);
}
public static void printNumber(int i)
{
if (i < 100)
{
System.out.println(i);
i = i + 1;
printNumber(i);
}
System.out.println(i);
}
}
but the code prints
0, 1, 2, ............100, 100, 99, ................1
So anyone please tell why it is printing 100,99,98.........1 and what went wrong?
EDIT I tried the logic to print 1 - 100 in all combinations and works well for me but output should be 1 - 99(print from inside condition) and finally 100(print by last print) but output is 1 - 100 and 100 - 1.
so please tell me why 100 to 1 is printing in output.
kindly dont tell me logic because I already got result what i expected