可以使用正则表达式来查找字符串中连续出现的数字,并判断是第几次迟到。以下是一个示例代码:

public class Main {
    public static void main(String[] args) {
        String status = "010102";
        int count = 0;
        int index = status.indexOf("1"); // 查找第一个出现的"1"
        while (index != -1) {
            count++;
            index = status.indexOf("1", index + 1); // 从下一个位置开始查找
        }
        System.out.println("第 " + count + " 次迟到");
    }
}

在上述示例中,我们使用indexOf()方法来查找字符串中第一个出现的"1"的位置,并使用一个while循环来查找下一个出现的"1"的位置,直到找不到为止。每找到一个"1",计数器count就加1。最后输出计数器的值即可得出是第几次迟到

java 异常状态String字段设定内容0为正常1为迟到2为早退3为旷工需求是查出当次是第几次迟到

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

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