In: Computer Science
For this assignment, you will apply what you learned in analyzing a simple Java™ program by writing your own Java™ program. The Java™ program you write should do the following:
Complete this assignment by doing the following:
Here is the code and please add comments
import java.util.Scanner;
public class PRG420Week1_CodingAssignment {
public static void main(String[] args) {
// Create a usable instance of an input device
LINE 1. INSTANTIATE AN INSTANCE OF SCANNER AND ASSIGN IT TO A
VARIABLE OF TYPE SCANNER.
// Prompt user for input
LINE 2. USE THE PRINT() METHOD TO PROMPT THE USER FOR HIS OR HER
FIRST NAME.
// Capture first word and assign it to A VARIABLE
LINE 3. USE THE NEXT() METHOD OF YOUR SCANNER INSTANCE TO ASSIGN A
VALUE TO A STRING VARIABLE.
// Construct the greeting
LINE 4. USE THE PRINTLN() METHOD TO CONSTRUCT A CORRECTLY
PUNCTUATED GREETING.
}
}
Java code
============================================================================================
package sat;
import java.util.Scanner;
public class PRG420Week1_CodingAssignment {
public static void main(String[] args) {
// TODO Auto-generated method
stub
String st;
// Create a usable instance of an
input device
Scanner sc = new
Scanner(System.in);
// Prompt user for input
System.out.print("Enter first name:
");
// Capture first word and assign
it to A VARIABLE
st=sc.next();
// Construct the greeting
System.out.println("Hello,"+st+"!");
}
}
============================================================================================
Output