Replace All pi Hint

What is wrong with my code
import java.util.*;
class Main{
public static String pi(String str,int i){
if(str.length()<=1)
return str;
String re=pi(str,i+1);
if(str.charAt(i)==‘p’ && str.charAt(i+1)=‘i’)
{
re=str.substring(0,i)+“3.14”+str.substring(i+1);
}
else
return re;
return str;
}
public static void main(String args[]){
String d=pi(“apidpi”,0);
System.out.println(d);

}}

@Sweta,
String re = pi(str, i + 1); this line will give stackoverflow because there is no base condition on maximum value of i. Hence it will give an infinite recursion and give stack overflow error

ok then if change it like this then again it showing return type is missing

class Main{
public static String pi(String str,int i){
if(str.length()<=1)
return str;
if(i==str.length())
return str;
String re=pi(str,i+1);
if(str.charAt(i)==‘p’ && str.charAt(i+1)=‘i’)
{
re=str.substring(0,i)+“3.14”+str.substring(i+1);
}
else
return re;

}
public static void main(String args[]){
String d=pi(“apidpi”,0);
System.out.println(d);

@Sweta,
If the “if” block is executed, there is no return type. Return type is mentioned only if the “else” block is executed.