2016-08-02 6 views
-4

パッケージ演習;forループを使用して文字列を連結する方法は?

import java.util.Scanner;

パブリッククラスSentenceBuilder forインサイド{

public static void main(String[] args) { 
    final int MAX_WORDS = 5; 

    Scanner scan = new Scanner(System.in); 
    String word =""; 

    for (int i = 0; i < MAX_WORDS; i++){ 
     System.out.println("Please enter word "+(i+1)+" of "+MAX_WORDS); 
     word = scan.nextLine(); 

    } 
    System.out.println(word);// im stuck on how to concatenate the result 

} 

}

+0

は 'StringBuilder'クラスを見てください。 – Bathsheba

答えて

0

word = word + scan.nextLine(); 
+0

助けてくれてありがとう – Jap

関連する問題