/** * @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; } }
本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
转载请注明出处: 免费源码网-免费的源码资源网站 » 最大字符串长度
发表评论 取消回复