Guest list of a hotel

Report a typo

There is a hotel that may accommodate 4 guests. Each line of the input contains the name or the names of the guests arriving at the hotel on a certain day.

Read the names of the guests from the input and output each name on a separate line and in reverse order starting with the last arrived guest. Note that the order of the arriving guests and the number of days are not pre-defined.

Tip: You don't need to use anything advanced for this task. Simply declare four strings and print them in reverse order.

Sample Input 1:

Jane Kate
John
Mary

Sample Output 1:

Mary
John
Kate
Jane

Sample Input 2:

Joseph 
Piotr Eugene
Jack

Sample Output 2:

Jack
Eugene
Piotr
Joseph
Write a program in Java 17
import java.util.Scanner;

class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String name1 = scanner.next(); // Scanning the first name out of 4 names, three more to go
// continue coding here
}
}
___

Create a free account to access the full topic