-4

package exercises;

import java.util.Scanner;

public class 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

}

}

Jap
  • 1

1 Answers1

0

Inside the for:

word = word + scan.nextLine();
Loris Securo
  • 7,538
  • 2
  • 17
  • 28