Printing strings in the same order

Report a typo

Write a program that reads exactly four words from the input and outputs them in the same order, but each in a new line.

Your program should declare four strings, read the input using the next() method, and print out each string in a new line.

Sample Input 1:

Hello
Java
Future programmer

Sample Output 1:

Hello
Java
Future
programmer
Write a program in Java 17
import java.util.Scanner;

class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// start coding here

sc.close();
}
}

Create a free account to access the full topic