package recursion;
public class recursion1 {
public static void print(int data)
{
if(data==0)
{
return;
}
System.out.println(data);
print(data–);
}
public static void main(String[] args) {
print(5);
}
}
package recursion;
public class recursion1 {
public static void print(int data)
{
if(data==0)
{
return;
}
System.out.println(data);
print(data–);
}
public static void main(String[] args) {
print(5);
}
}
see this
public static void main(String[] args) {
int x=5;
System.out.println(x-1);
System.out.println(x--);
System.out.println(x);
}
see this print 4 then 5 then 4 cause Well, although the value of x
will be same, they are different operators, and use different JVM instructions in bytecode. x-- is postfix decrement operator, this means that the value of x is first used in the program and then decremented so it becomes a long loop for your code and hence the error