Write a complete Java program which prompts the user of the program to input his/her first name, then prompts the user for the middle initial and finally prompts the user for the last name. As indicated, there are three prompts to the user. The program should output the user’s name with the first name first, followed by the middle initial, and the last name last, all on one line (with appropriate spacing).
If you could also pinpoint exactly where to place the names in the code that would be greatly appreciated.
import java.util.Scanner; public class UserName { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter first name: "); String first = in.next(); System.out.print("Enter middle initial: "); String middle = in.next(); System.out.print("Enter last name: "); String last = in.next(); System.out.println(first + " " + middle + " " + last); } }
Get Answers For Free
Most questions answered within 1 hours.