Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I'm working on a simple Java program that is looking for the following, Create a project that asks the users name, then reverses them.

Hi, I'm working on a simple Java program that is looking for the following,

Create a project that asks the users name, then reverses them. The first name needs to be reversed and used as the first name, and the last name needs to be reversed and used as the last name. That is, if the users name is Hal Morgan, the reversed version is Lah Nagrom, first name is still first, last name is still last. Notice that the first letter of each name must be capitalized.

This is what I have so far: public static void main(String[] args)

{ Scanner stdIn = new Scanner(System.in);

String name, backwards = ""; int i, length;

System.out.print("What is your name? ");

name = stdIn.nextLine(); length = name.length();

for (i = length - 1; i >= 0; i--)

{ backwards += name.charAt(i); name = Character.toUpperCase(name.charAt(0)) + name.substring(1); }

System.out.println("It's a backwards day! " + backwards );

The problem is that it is not putting the first name first, and the last name last. How do I make sure the first name is still first(but backwards), and the last name last(still backwards)?

Rigth now it prints out " It's a backwards day! nagrom laH"

And I need it to print out "It's a backwards day! Lah Nagrom"

Thanks

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

Data Management Databases And Organizations

Authors: Richard T. Watson

6th Edition

1943153035, 978-1943153039

More Books

Students also viewed these Databases questions

Question

Describe five artifacts of culture and give an example of each.

Answered: 1 week ago

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago