兰聪


私信TA

用户名:dotcpp0606174

访问量:914

签 名:

等  级
排  名 2827
经  验 2060
参赛次数 0
文章发表 13
年  龄 0
在职情况 学生
学  校 鄂州职业大学
专  业

  自我简介:

TA的其他文章

参考代码:

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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区