最大字符串长度

复制代码
/**
 * @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;
    }
}
相关推荐
小马爱打代码1 小时前
Spring Boot:模块化实战 - 保持清晰架构
java·spring boot·架构
岁忧1 小时前
GoLang五种字符串拼接方式详解
开发语言·爬虫·golang
tyatyatya1 小时前
MATLAB基础数据类型教程:数值型/字符型/逻辑型/结构体/元胞数组全解析
开发语言·matlab
小坏讲微服务1 小时前
SpringBoot4.0整合knife4j 在线文档完整使用
java·spring cloud·在线文档·knife4j·文档·接口文档·swagger-ui
8***Z891 小时前
springboot 异步操作
java·spring boot·mybatis
i***13242 小时前
Spring BOOT 启动参数
java·spring boot·后端
坚持不懈的大白2 小时前
后端:SpringMVC
java
IT_Octopus2 小时前
(旧)Spring Securit 实现JWT token认证(多平台登录&部分鉴权)
java·后端·spring
kk哥88992 小时前
Spring详解
java·后端·spring
S***26752 小时前
Spring Cloud Gateway 整合Spring Security
java·后端·spring