Loop is executing for one less time than required

if the value of t=3, output is shown for only 2 cases.
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=1;i<=t;i++)
{
String s=sc.nextLine();
remPi(s+" ",1);

	}

}
public static void remPi(String s,int i)
{
if(i>=s.length()){
System.out.println(s);
return;
}
if(s.charAt(i)==ā€˜i’ && s.charAt(i-1)==ā€˜p’)
{
s=s.substring(0,i-1)+ā€œ3.14ā€+s.substring(i+1);
}
remPi(s,i+1);
}
}

@d1sha_singh when using nextline after next it is reading the blank space after the integer.
u can add an extra s.nextline(); after u input the integer .

int t=sc.nextInt();
sc.nextLine();
for(int i=0;i<t;i++){
String s=sc.nextLine();
remPi(s+" ",1);
}

1 Like