如何使用扫描仪连接for循环中的字符串?

时间:2016-08-02 12:02:01

标签: java

包裹练习;

import java.util.Scanner;

公共类SentenceBuilder {

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

}

}

1 个答案:

答案 0 :(得分:0)

for

word = word + scan.nextLine();