参考代码:
package dotcpp; import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); String str = s.substring(0, s.indexOf('.') + 1); // substring:字符串截取 char type = sc.next().charAt(0); if (type == 'D') { char del = sc.next().charAt(0); System.out.println(str.replaceFirst(del + "", "")); // replaceFirst:替换第一个 } else if (type == 'I') { char chosen = sc.next().charAt(0); // 选定的字符 char ins = sc.next().charAt(0); // 需要插入的字符 int index = str.lastIndexOf(chosen); // lastIndexOf:字符最后一次出现的位置 System.out.println(str.substring(0, index) + ins + str.substring(index)); } else if (type == 'R') { char chosen = sc.next().charAt(0); // 选定的字符 char update = sc.next().charAt(0); // 需要替换的字符 System.out.println(str.replaceAll(chosen + "", update + "")); // replaceAll:替换全部 } } }
0.0分
2 人评分
C语言程序设计教程(第三版)课后习题6.6 (C++代码)浏览:633 |
用筛法求之N内的素数。 (C语言代码)浏览:806 |
P1000 (C语言代码)浏览:877 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:517 |
大家好,我是验题君浏览:577 |
The 3n + 1 problem (C语言代码)浏览:505 |
陈教主的三角形 (C语言代码)浏览:1143 |
简单的a+b (C语言代码)浏览:540 |
多输入输出练习2 (C语言代码)浏览:1656 |
1231题解(注意理解“输入多个测试实例”)浏览:788 |