UnknownUser_66

D286 - 3.26

Jan 10th, 2024
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class NameFormat {
  4.     public static void main(String[] args){
  5.         Scanner scnr = new Scanner(System.in);
  6.         String firstName, middleName, lastName;
  7.  
  8.         firstName = scnr.next();
  9.         middleName = scnr.next();
  10.         lastName = scnr.nextLine();
  11.  
  12.         if (lastName.equals("")){
  13.             System.out.println(middleName + ", " + firstName.charAt(0) + ".");
  14.         } else {
  15.             lastName = lastName.substring(1);
  16.             System.out.println(lastName + ", " + firstName.charAt(0) + "." + middleName.charAt(0) + ".");
  17.         }
  18.  
  19.         scnr.close();
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment