Display three messages

The problem

In this exercise you will write a program that displays the following strings to the console:

  • Welcome to Java
  • Welcome to Computer Science
  • Programming is fun

Breaking it down

Java 8 provides a way to create a stream of strings by calling the Stream.of while passing one to many arguments. Then calling the Stream.forEach passing in a referencing to System.out::println will print the stream elements.

public static void main(String[] args) {

    Stream.of("Welcome to Java", "Welcome to Computer Science",
            "Programming is fun").forEach(System.out::println);

}

Output

Welcome to Java
Welcome to Computer Science
Programming is fun