On execution in Eclipse it works perfectly
On execution on this platform it only says Run Error
The following is the code in the Main class
private static Scanner sc;
private static Scanner in;
public static void main(String[] args) {
// TODO Auto-generated method stub
sc=new Scanner(System.in);
in=new Scanner(System.in);
int n=sc.nextInt();
String[] arr=new String[n];
for(int i=0;i<n;i++) {
arr[i]=in.nextLine();
}
sc.close();
for(String str: arr)
System.out.println(replacePi(str));
}
public static String replacePi(String str) {
if(str.length()==1) {
return str;
}
String x=replacePi(str.substring(1));
if(str.charAt(0)==βpβ&&str.charAt(1)==βiβ) {
String ans=β3.14β+x.substring(1);
return ans;
}
else return str.charAt(0)+x;
}
Run error on execution in online platform
@Rishabh8488,
https://ide.codingblocks.com/s/241242 corrected code.
Donβt use 2 scanner objects for input.
Use .next for input of string instead of nextLine.
Your recursion logic is correct.
I hope Iβve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.