Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will prompt a user to input their name (first and last). Ex

ID: 3937128 • Letter: W

Question

Write a program that will prompt a user to input their name

(first and last).

Ex: Please enter your first and last name:    John Doe

Then, output the string.

Next, prompt the user to input their nickname.

Ex: Enter your nickname:   Rowdy

Then modify the name string to consist of the person’s first name, nickname (in all caps, enclosed in double quotes) and last name.

Then output the modified string.

Ex: John “ROWDY” Doe

NOTE: This program should loop, prompting the user to decide whether or not he or she wishes to enter another name.

Ex: Do you wish to enter another name(y/n)?

Explanation / Answer


import java.util.Scanner;

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

public class MainClass {
  
public static void main(String[] args) {
  
Scanner input = new Scanner(System.in);
String name,nickname,first,last;
char choice;
do
{
System.out.println("Please enter your first and last name: ");
name = input.nextLine();

System.out.println("Your name is : "+name);

System.out.println("Please enter your nickname");
nickname = input.nextLine();
nickname = nickname.toUpperCase();

first = name.split(" ")[0];
last = name.split(" ")[1];

name = first + " "" + nickname + "" " + last;
System.out.println("Modified name is : "+name);

System.out.println("Do you wish to enter another name(y/n)?");
choice = input.next().toLowerCase().charAt(0);
input.nextLine();
}while(choice!='n');
}
}

OUTPUT:

run:
Please enter your first and last name:
John Doe
Your name is : John Doe
Please enter your nickname
Rowdy
Modified name is : John "ROWDY" Doe
Do you wish to enter another name(y/n)?
y
Please enter your first and last name:
David Beckham
Your name is : David Beckham
Please enter your nickname
Becks
Modified name is : David "BECKS" Beckham
Do you wish to enter another name(y/n)?
n
BUILD SUCCESSFUL (total time: 18 seconds)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote