58. 最后一个单词的长度
package leetcode; public class demo_58 { public int lengthOfLastWord(String s) { String [] str=s.split(" "); if(s=="") {return 0;} try { if(str[str.length-1]!="") { return str[str.length-1].length(); } } catch (Exception e) { // TODO: handle exception } return 0; } public static void main(String[] args) { // TODO Auto-generated method stub demo_58 d58=new demo_58(); System.out.println(d58.lengthOfLastWord("hello world")); } }
浙公网安备 33010602011771号