Skip to content

Commit dfb994d

Browse files
committed
pi solution
1 parent 7c1822a commit dfb994d

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

GeeksForGeeks/replacepi.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//replacing pi with 3.14
2+
3+
public class replacepi {
4+
//Here we search the characterand if it match we change
5+
public static String pi(String str) {
6+
if(str.length()<2){
7+
return str;
8+
}
9+
else{
10+
String firsttwo=str.substring(0, 2);
11+
if(firsttwo.equals("pi")){
12+
return "3.14"+pi(str.substring(2));
13+
}
14+
else{
15+
return str.charAt(0)+pi(str.substring(1));
16+
}
17+
}
18+
}
19+
20+
21+
public static void main(String[] args) {
22+
String str="xpix";
23+
String ans=pi(str);
24+
System.out.println(ans);
25+
}
26+
}

0 commit comments

Comments
 (0)