Complete the following code to get the user's last name from the console. Your code must declare and initialize a variable of the appropriate type with the console input. Use the appropriate Scanner class API among the list of API's listed below. Scanner in = new Scanner(System.in); Scanner class API's: String next(): Find ands return the next complete token from this scanner. double nextDouble(): Scans the next token of the input as a double. int nextInt(): Scans the next token of the input as an int.
Added by Robert D.
Close
Step 1
First, we need to import the Scanner class from the java.util package: ```java import java.util.Scanner; ``` Show more…
Show all steps
Your feedback will help us improve your experience
Corbin Tegner and 54 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Write a program that asks the user to input their first and last names. The first prompt should state: Please input your first name: The second prompt should state: Please input your last name: After accepting the inputs, your program should output the input in the form last name, first name. Hint: Remember that you can concatenate (add) two phrases by using the + symbol. Don't forget that you'll need to add a comma as well and that the comma must be followed by a space.
Akash M.
The objective of this simple assignment is to write a simple program, just to make sure you can edit, compile and run a C++ program via Vocareum system.Write a C++ program that displays a message as "Welcome to CS 280.", and prompts the user to enter his or her first and last names "What is your first and last names?". The program should read the user's first and last names as strings and display a welcoming message that includes the student's full name. A full dialogue example is shown below:Welcome to CS 280.What is your first and last names?George FritzHello, George Fritz Note: Use the same format and phrases for the input and output as shown for full credit. However, testing your program on your environment would require an input from the user to be entered for the name. For automatic grading on Vocareum, the input will be provided from an input file which includes some name instead, for example "George" in the example above.
Supreeta N.
Question 5: Write a program that reads a person's name in the following format: first name, then middle name or initial, and then last name. The program then outputs the name in the following format: Last_Name, First_Name Middle_Initial. For example, the input "Mary Average User" should produce the output: "User, Mary A". The input "Mary A.User" should also produce the output: "User, Mary A". Note that your program should work the same and place a period after the middle initial even if the input did not contain a period. Hint: You may want to use three string variables rather than one large string variable for the input. You may find it easier to not use getline.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Watch the video solution with this free unlock.
EMAIL
PASSWORD