/**
 * @author gyf
 * @ClassName Test
 * @Date 2024/8/3 17:22
 * @Version V1.0
 * @Description :
 */
public class Test {
    public static void main(String[] args) {
        String s1 = "Hello World ";
        System.out.println(getLength(s1));
        String s2 = "fly me to the moon";
        System.out.println(getLength(s2));
        String s3 = "luccy is still joybys";
        System.out.println(getLength(s3));
    }

    public static int getLength(String str) {
        int length = 0;
        for (int i = str.length() - 1; i >= 0; i--) {
            if (str.charAt(i) != ' ') {
                length++;
            } else {
                break;
            }
        }
        return length;
    }
}

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部