package day1; import java.util.Scanner; public class Main{ public static void main(String[] args) { int i; Scanner input = new Scanner(System.in); //从键盘获取字符串 String strInput = input.nextLine(); //将Scanner对象中的内容以
package day1; import java.util.Scanner; public class Main{ public static void main(String[] args) { int i; Scanner input = new Scanner(System.in); //从键盘获取字符串 String strInput = input.nextLine(); //将Scanner对象中的内容以字符串的形式取出来 char arr[]=strInput.toCharArray(); for( i=arr.length-1;i>=0;i--){ if(arr[i]==' ') break; } int length=arr.length-i; char output[]=new char[length-1]; int k=0; for(int j=i+1;j<=arr.length-1;j++){ output[k]=arr[j]; k++; } System.out.println("最后一个单词:"); System.out.println(output); System.out.println("最后一个单词的长度:"); System.out.println(k); input.close(); } }