Write a Java program that gets strings containing a person’s first name and last name as separate values, and then displays their “initials”, “name in address book”, and “username”. For example, if the user enters a first name of “John” and a last name “Smith”, the program should display “J.S.”, “John SMITH”, and “jsmith”.
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
String fname;
String lname;
System.out.println("Enter first name: ");
fname=in.next();
System.out.println("Enter last name: ");
lname=in.next();
char f1=fname.charAt(0);
char f2=lname.charAt(0);
System.out.print("Initials: "+f1+"."+f2+"."+"\n");
System.out.print("Name in address book: "+fname+" "+lname.toUpperCase()+"\n");
String username=f1+lname;
System.out.print("Username: "+username.toLowerCase()+"\n");
}
}
Output
Comments
Leave a comment