Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class PiReplace {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String stringToReplace = scanner.nextLine();
- String stringAfterReplace = replace(stringToReplace);
- System.out.println("Before - " + stringToReplace + " After - " + stringAfterReplace);
- }
- public static String replace(String str) {
- if (str.length() <= 1) {
- return str;
- }
- if (str.charAt(0) == 'p' && str.charAt(1) == 'i') {
- return "3.14" + replace(str.substring(2));
- }
- return str.charAt(0) + replace(str.substring(1));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment