In: Computer Science
jgrasp environment, java
write a complete program that prompts the user to enter their first name, middle name, and last name (separately). print out thier name and initials, exactly as shown:
your name is: John Paul Chavez
your initials are: J. P. C.
use string method chartAt() to extract the first (zero-th) character from a name(the name is a string type): username.charAt(0).
thank you.
Program :
import java.util.Scanner; // Import the Scanner class
class Myclass
{
public static void main(String args[])
{
Scanner obj = new Scanner(System.in); // Create a Scanner
object
System.out.println("Enter your
first name:");
String FirstName = obj.nextLine();
System.out.println("Enter your middle name:");
String MiddleName = obj.nextLine();
System.out.println("Enter your middle name:");
String LastName = obj.nextLine();
System.out.println("your name is:"+FirstName+" "+MiddleName+"
"+LastName);
System.out.println("your initials
are:"+FirstName.charAt(0)+"."+MiddleName.charAt(0)+"."+LastName.charAt(0)+".")
}
}
Screen shot of the program with out put: