Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started