CHALLENGE ACTIVITY
1.25.2: Reading and outputting strings.
Write a program that reads a person's first and last names separated by a space, assuming the first and last names are both single words. Then the program outputs last name, first name. End with newline.
Example output if the input is: Maya Jones
Jones, Maya
See How to Use zyBooks for info on how our automated program grader works.
1 import java.util.Scanner;
2
3 public class SpaceReplace {
4 public static void main(String[] args) {
5 Scanner scnr = new Scanner(System.in);
6 String firstName;
7 String lastName;
8
9 System.out.println(lastName + ", " + firstName);
10
11
12
13 }
14 }
Run
Failed to compile
SpaceReplace.java:11: error: variable lastName might not have been initialized
System.out.println(lastName + ", " + firstName);
SpaceReplace.java:11: error: variable firstName might not have been initialized
System.out.println(lastName + ", " + firstName);
2 errors
Feedback?