我需要从用户那里获取一些单词,然后输出一个最终单词,该单词由用户输入的单词的最后一个字母的连接形成。
这是代码。但是我如何从循环中取出这些字母并将它们连接起来?
import java.util.Scanner;
public class newWord {
public static void main(String args[]) {
System.out.println("How many words are you going to enter?");
Scanner num = new Scanner(System.in);
int number = num.nextInt();
System.out.println("Please Enter the "+number+" words:");
for(int n=1;n<=number;n++)
{
Scanner words = new Scanner(System.in);
String thisword = words.nextLine();
char str2 = thisword.charAt(thisword.length()-1);
System.out.println(str2);
}
}
}