我需要從用戶處獲取一些單詞,然後輸出一個由單詞最後一個字母連接而成的最終單詞用戶有輸入。通過連接Java中給定字符串集的最後一個字母來創建一個新字符串
這是代碼。但是,我如何從循環中提取這些字母並連接它們?
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);
}
}
}
謝謝大家對你的幫助。提示或代碼,我正在學習:) – Sabharish 2013-02-23 07:38:56