Getting "Stack Overflow Error". Please help

package recrusion_practice;

import java.util.Scanner;

public class ReplaceofPi {

public static void main(String[] args) {
	
	Scanner scn = new Scanner(System.in);
	
	int t = scn.nextInt();
	
while(t>0) {
	int index = 0;
	String n = scn.next();
	//pi(n,index);
	
	System.out.print(pi(n,index));
	t--;
}
	
	
}

static String pi(String n, int ind) {
	
	if(n.length()<=1) {
		return n;
	}
	

 String ans=pi(n,ind+1);
 
 if(ans.charAt(ind)=='p'&& ans.length() >= 2 && ans.charAt(ind+1)=='i') 
 {
	 ans = ans.substring(0,ind)+"3.14"+ans.substring(ind+2);
 }
 return ans;
}

}

your base condition is incorrect. as in next recursion call, you are increasing index value to ind+1, you must write your base condition on index value.
like if(ind == n.length()-1)
{
return n;}
Stack overflow error comes when your recursion does not stop after some point.
always check base condition of recursion in this kind of error.

Thanks.

Still not getting answer but changing base condition it only prints 3.14

your code should be:
package recrusion_practice;

import java.util.Scanner;

public class ReplaceofPi {

public static void main(String[] args) {

Scanner scn = new Scanner(System.in);

int t = scn.nextInt();

while(t>0) {
int index = 0;
String n = scn.next();
//pi(n,index);

System.out.print(pi(n,index));
t--;

}

}

static String pi(String n, int ind) {

if(n.length()-1==ind) {
	return n;
}

String ans=pi(n,ind+1);

if(ans.charAt(ind)==ā€˜p’&& ans.length() >= 2 && ans.charAt(ind+1)==ā€˜i’)
{
ans = ans.substring(0,ind)+ā€œ3.14ā€+ans.substring(ind+2);
}
return ans;
}

}

please let me know which test case fails for you?

Thanks