Advertisement
advictoriam

Untitled

Nov 28th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.    A program that reads in a first name, a middle name, and a last name,
  5.       and then print out the three initials as a single string.
  6.    For example, if the three input names are James, Paul, and Jones,
  7.       then the output should be JPJ.
  8. */
  9. public class Initials
  10. {
  11.    public static void main (String[] args)
  12.    {
  13.       // Display prompts for all three names
  14.       System.out.println("Please enter first name, middle name, last name: ");
  15.  
  16.       // Read names
  17.       Scanner in = new Scanner(System.in);
  18.       String fName = in.next();
  19.       String mName = in.next();
  20.       String lName = in.next();
  21.  
  22.       // Print out the initials
  23.       System.out.print(fName.charAt(0));
  24.       System.out.print(mName.charAt(0));
  25.       System.out.println(lName.charAt(0));
  26.    }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement