方法一:
public int getFinalWordLen(){ String[] words= new String[128]; int len=0; int num=0; Scanner sc= new Scanner(System. in); words=sc.nextLine().split( " "); num=words. length; if(sc== null) { len=0; } else{ String finalWord=words[num-1]; len=finalWord.length(); } return len; }
方法二:
public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()){ String[] strings=sc.nextLine().split(" "); System.out.println(strings[strings.length-1].length()); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/shangqing1123/article/details/48047111