你可以使用Java的String类的substring()方法来实现这一功能。该方法可以截取字符串的子串。

下面是一个示例代码:

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入字符串:");
        String input = scanner.nextLine();

        int index = input.indexOf(":"); // 查找第一个英文冒号的位置
        if (index != -1) {
            String output = input.substring(index + 1); // 截取冒号后的子串
            System.out.println("冒号后的字符串为:" + output);
        } else {
            System.out.println("输入的字符串中没有冒号。");
        }
    }
}

运行程序后,你可以输入一个字符串。程序将会输出该字符串中第一个英文冒号后的字符串。如果输入的字符串中没有冒号,程序会给出相应提示。

示例输入和输出:

输入:Hello: World! 输出:冒号后的字符串为: World!

输入:Hello World! 输出:输入的字符串中没有冒号

java中输入一个字符串要求输出第一个英文冒号后的字符串不包含该冒号

原文地址: https://www.cveoy.top/t/topic/it2M 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录