HIDE NAV

Greeter

The below command line program demonstrates how to perform basic input and output on a text terminal in core Java.
The Scanner class is used to take input from the user. and String variables are used to hold all data.

Main.java


package ceccs;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        /** variables to store our inputs, and greeting */
        String firstName, lastName, greeting;
        System.out.println("This is a greeter program.");
        System.out.println("Enter your first name:");
        /** create a scanner to read user input */
        Scanner scan = new Scanner(System.in);
        /** user inputs first name, we store it in our variable */
        firstName = scan.nextLine();

        System.out.println("Enter your last name:");
        lastName = scan.nextLine();

        /** build a string to output the greeting */
        greeting = "Hello, " + firstName + " " + lastName
                + ", Welcome to computer science!";
        System.out.println(greeting);

    }
}