import java.util.Scanner;
public class pratice1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
while(s.hasNextLine()){
String s1;
s1= s.nextLine();
int a= s1.lastIndexOf(" ");
System.out.println(s1.length()-1-a);
}
}
public class pratice1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
while(s.hasNextLine()){
String s1;
s1= s.nextLine();
int a= s1.lastIndexOf(" ");
System.out.println(s1.length()-1-a);
}
}
}
新建一个scanner对象用于读取字符串。
scanne.next line()函数用于读取;
字符串对象string.lastindexof()函数找某个字符的位置。