SlideShare a Scribd company logo
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)?
Solution
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)

More Related Content

PPTX
Chapter 2.4
PPTX
PDF
Lecture 0 - CS50's Introduction to Programming with Python.pdf
PDF
Hi, I need help with a java programming project. specifically practi.pdf
PPTX
PPTX
SPF Getting Started - Console Program
PPTX
Getting Started - Console Program and Problem Solving
PPTX
Lecture - 2 Environment setup & JDK, JRE, JVM
Chapter 2.4
Lecture 0 - CS50's Introduction to Programming with Python.pdf
Hi, I need help with a java programming project. specifically practi.pdf
SPF Getting Started - Console Program
Getting Started - Console Program and Problem Solving
Lecture - 2 Environment setup & JDK, JRE, JVM

Similar to Write a program that will prompt a user to input their name(first .pdf (20)

PDF
Be sure to import javautilScanner Name the class PersonalD.pdf
PDF
GLA-01- Java- Big O and Lists Overview and Submission Requirements You.pdf
DOCX
Java execise
PPT
Jacarashed-1746968053-300050282-Java.ppt
PPT
Android coding guide lines
PDF
Object Oriented Solved Practice Programs C++ Exams
DOCX
Unit2 java
PPT
Clean code _v2003
PPSX
Writing code that writes code - Nguyen Luong
PPSX
TechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
DOCX
JAVA Q2- Write a program that reads strings from the user and writes t.docx
DOCX
Chapter 2 -ava Fundamentals Code Listing 2-32 (NameaDialog- Java) Unit.docx
PDF
Dev Day Andreas Roth.pdf
PPTX
JAVA_SAMPLE CODING, JAVA BASICS PROGRAMS.pptx
PPTX
Lecture-5Programming WorldJava Lecture.pptx
PPTX
Lab 01hhkhkhkhkhkhkhkhkhjjjkhkkhhhhh.pptx
PPTX
Lab 01jbjbjkbkbjkbkjbkjbkbkjbbnjjkb.pptx
PPT
M251_Meeting 7 (Exception Handling and Text IO).ppt
DOCX
PAGE 1Input output for a file tutorialStreams and File IOI.docx
PPT
Introduction
Be sure to import javautilScanner Name the class PersonalD.pdf
GLA-01- Java- Big O and Lists Overview and Submission Requirements You.pdf
Java execise
Jacarashed-1746968053-300050282-Java.ppt
Android coding guide lines
Object Oriented Solved Practice Programs C++ Exams
Unit2 java
Clean code _v2003
Writing code that writes code - Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
JAVA Q2- Write a program that reads strings from the user and writes t.docx
Chapter 2 -ava Fundamentals Code Listing 2-32 (NameaDialog- Java) Unit.docx
Dev Day Andreas Roth.pdf
JAVA_SAMPLE CODING, JAVA BASICS PROGRAMS.pptx
Lecture-5Programming WorldJava Lecture.pptx
Lab 01hhkhkhkhkhkhkhkhkhjjjkhkkhhhhh.pptx
Lab 01jbjbjkbkbjkbkjbkjbkbkjbbnjjkb.pptx
M251_Meeting 7 (Exception Handling and Text IO).ppt
PAGE 1Input output for a file tutorialStreams and File IOI.docx
Introduction
Ad

More from omarionmatzmcwill497 (20)

PDF
CenTable - Requirements Specification CenTable is a system for creati.pdf
PDF
Are silenced genes associated with high or low levels of DNA methyla.pdf
PDF
A south facing window is 2.1 m high and 4.2 m long. A horizontal diff.pdf
PDF
Write an extended summary (They say”) of Sheryl Sandbergs Lean.pdf
PDF
With a blow count of 14 the density of the soil is Select one 15e bit.pdf
PDF
Which process(es) can move solutes against concentration gradients (.pdf
PDF
What role do piRNAs play Serve as atemplate for transposon silencin.pdf
PDF
what was the PRIMARY cause of the current Greece Crisis Excessive g.pdf
PDF
Three LR circuits are made with the same resistor but different induc.pdf
PDF
There are several things fundamentally wrong in this illustration. Po.pdf
PDF
The poor are available to do the unpleasant jobs that no one .pdf
PDF
Suppose that 14 of people are left handed. If you pick two people a.pdf
PDF
Please help me with these General Biology 1 (Bio 111) questions. You.pdf
PDF
NEED HELP ON C HOMEWORKIntroduction Programmers for a Better Tomo.pdf
PDF
Problem 14. Your probability class has 250 undergraduate students and.pdf
PDF
Simplify each expression. Write all ansers without using negative ex.pdf
PDF
Our understanding of genetic inheritance and the function of DNA i.pdf
PDF
Please Explain. Compute the worst case time complexity of the follow.pdf
PDF
3. Variance of exponential and uniform distributions(a) Compute Va.pdf
PDF
Prove using a common notion that if P and Q are any points on a circ.pdf
CenTable - Requirements Specification CenTable is a system for creati.pdf
Are silenced genes associated with high or low levels of DNA methyla.pdf
A south facing window is 2.1 m high and 4.2 m long. A horizontal diff.pdf
Write an extended summary (They say”) of Sheryl Sandbergs Lean.pdf
With a blow count of 14 the density of the soil is Select one 15e bit.pdf
Which process(es) can move solutes against concentration gradients (.pdf
What role do piRNAs play Serve as atemplate for transposon silencin.pdf
what was the PRIMARY cause of the current Greece Crisis Excessive g.pdf
Three LR circuits are made with the same resistor but different induc.pdf
There are several things fundamentally wrong in this illustration. Po.pdf
The poor are available to do the unpleasant jobs that no one .pdf
Suppose that 14 of people are left handed. If you pick two people a.pdf
Please help me with these General Biology 1 (Bio 111) questions. You.pdf
NEED HELP ON C HOMEWORKIntroduction Programmers for a Better Tomo.pdf
Problem 14. Your probability class has 250 undergraduate students and.pdf
Simplify each expression. Write all ansers without using negative ex.pdf
Our understanding of genetic inheritance and the function of DNA i.pdf
Please Explain. Compute the worst case time complexity of the follow.pdf
3. Variance of exponential and uniform distributions(a) Compute Va.pdf
Prove using a common notion that if P and Q are any points on a circ.pdf
Ad

Recently uploaded (20)

PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Computing-Curriculum for Schools in Ghana
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
My India Quiz Book_20210205121199924.pdf
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PPTX
Introduction to Building Materials
PPTX
Computer Architecture Input Output Memory.pptx
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
HVAC Specification 2024 according to central public works department
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
Indian roads congress 037 - 2012 Flexible pavement
PDF
IGGE1 Understanding the Self1234567891011
Unit 4 Computer Architecture Multicore Processor.pptx
Weekly quiz Compilation Jan -July 25.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Computing-Curriculum for Schools in Ghana
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
My India Quiz Book_20210205121199924.pdf
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
A powerpoint presentation on the Revised K-10 Science Shaping Paper
FORM 1 BIOLOGY MIND MAPS and their schemes
Introduction to Building Materials
Computer Architecture Input Output Memory.pptx
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
HVAC Specification 2024 according to central public works department
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
AI-driven educational solutions for real-life interventions in the Philippine...
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Indian roads congress 037 - 2012 Flexible pavement
IGGE1 Understanding the Self1234567891011

Write a program that will prompt a user to input their name(first .pdf

  • 1. 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)? Solution 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);
  • 2. 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)