0

hi can someone explain this small code how its work :

```
/**
* @(#)Output.java
*
*
* @author
* @version 1.00 2011/12/24
*/
public class Output {
public static int rec(int x, int n)
{
if (n < 0)
{
System.out.println("Illegal argument");
System.exit(0);
}
if (n > 0)
return ( rec(x, n - 1)*x );
else
return 1;
}
public static void main(String[] args) {
for (int n = 1; n < 3; n++)
System.out.println("3^" +n+ " is " + rec(3, n));
}
}
```

output:

3^1 is 3

3^2 is 9

---

and the other is

```
public class Q3E {
public static void main(String[] args) {
System.out.println(recursive(158));
}
public static int recursive(int n) {
if (n > 0)
return recursive(n/10) + 1;
else
return 0;
}
}
```

output= 3

*Edited 4 Years Ago by programing*: n/a