2024_Programming_Training_D.../CS2 - Challenge Solution/Main.java

23 lines
764 B
Java

import java.util.Scanner;
/*
CS2 Challenge Solution
Original Challenge Description: Build a program that requests a user's name,
and then prints a greeting.
*/
public class Main {
public static void main(String[] args) {
//Setup a Scanner to work with System.in
Scanner scan = new Scanner(System.in);
//Start by printing some text that will prompt the user to enter a name
//then print another line that Says "Hello" and then whatever the user entered.
System.out.print("Please enter your name: ");
System.out.println("Hello " + scan.nextLine());
//Close the scanner, while not really necessary, it's a good habit to get into
//for other resources.
scan.close();
}
}