Answer to Question #235893 in Java | JSP | JSF for Ding

Question #235893

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”.



1
Expert's answer
2021-09-11T23:39:24-0400
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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS