Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4.8 Lab Warmup: String Input and Formatting The template reads a person's first and last name into String variables. Edit the program template to: Create

4.8 Lab Warmup: String Input and Formatting

The template reads a person's first and last name into String variables. Edit the program template to: Create the variables for a second person's first and last names. Read the second person's first name and last name into the separate string variables. Assumptions: The first and last names contain no spaces and are no longer than 12 characters each. Then use printf to display the names, formatted exactly as follows, so the commas line up. Since none of the last names will be longer than 12 characters, display 12 characters before the comma. Hints: Use the width specifier to line up the last names. Use the precision specifier to display only the first letter of each person's name Output a newline after each name is displayed. Example:

Enter one person's first and last name: Paul Revere Enter a second person's first and last name: Martha Washington Revere, P Washington, W

import java.util.Scanner;

public class StringFormatting { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String firstName1 = ""; String lastName1 = ""; // FIXME: Create variables System.out.println("Enter a person's first and last name:"); firstName1 = keyboard.next(); lastName1 = keyboard.next(); // FIXME: Prompt for and read second person's name System.out.println(); // FIXME: Display formatted names return; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Upgrade Migration And Transformation Tips And Techniques

Authors: Edward Whalen ,Jim Czuprynski

1st Edition

0071846050, 978-0071846059

More Books

Students also viewed these Databases questions

Question

recognise typical interviewer errors and explain how to avoid them

Answered: 1 week ago

Question

identify and evaluate a range of recruitment and selection methods

Answered: 1 week ago

Question

understand the role of competencies and a competency framework

Answered: 1 week ago