Jump to content

Name Reversal in Java

Go to solution Solved by prolemur,

I would create a for loop that starts at the end of the string (using the string.length() to get this) then output the letters from last to first with system.out.print(namestring.charAt(variable used in for loop));

 

Sorry I couldn't check this right now, but that's how I'd tackle it.

So for my Computer Science class we use Blue Pelican Java. This lesson they tell us to reverse the name that is typed in. They never taught us this so I'm at a lost. They also don't teach how to enter a full name besides one at a time. Is There a way to enter "John Smith" vs. "John" + "Smith"?

 

 

            Project… Name Reversal

            Write a program that will allow a user to input his name. The prompt and input data would look something like this:

            Please enter your name. Peter Ustinov

            Using a for-loop and the String method, substring(…),  produce a printout of the reversal of the name.

            For example, the name Peter Ustinov would be:

            vonitsu retep

            Notice that the printout is in all lower-case. Use the String method, toLowerCase( ) to accomplish this.

 

package nameReversal;

import java.io.*;
import java.util.*;

public class Tester {

    public static void main(String[] args) {
        
        Scanner kbReader = new Scanner(System.in);
        System.out.print("What's your name?_");
        String a = kbReader.next();
        
        for
            
        }
        
    }

}

 

Current System: CPU - I5-6500 | Motherboard - ASRock H170M-ITX/ac | RAM - Mushkin Blackline 16GB DDR4 @ 2400mHz | GPU - EVGA 1060 3GB | Case - Fractal Design Nano S | Storage - 250GB 850 EVO, 3TB Barracuda | PSU - EVGA 450W 80+ Bronze | Display - AOC 22" 1080p IPS | Cooling - Phanteks PH-TC12DX_BK | Keyboard - Cooler Master QuickFire Rapid(MX Blues) | Mouse - Logitech G602 | Sound - Schiit Stack | Operating System - Windows 10

 

The OG System: I3-2370M @ 2.4 GHz, 750GB 5400 RPM HDD, 8GB RAM @1333Mhz, Lenovo Z580 Laptop (Ubuntu 16.04 LTS).

 

Peripherals: G602, AKG 240, Sennheiser HD 6XX, Audio-Technica 2500, Oneplus 5T, Odroid C2(NAS).

Link to comment
https://linustechtips.com/topic/216692-name-reversal-in-java/
Share on other sites

Link to post
Share on other sites

I would create a for loop that starts at the end of the string (using the string.length() to get this) then output the letters from last to first with system.out.print(namestring.charAt(variable used in for loop));

 

Sorry I couldn't check this right now, but that's how I'd tackle it.

Link to comment
https://linustechtips.com/topic/216692-name-reversal-in-java/#findComment-2970153
Share on other sites

Link to post
Share on other sites

I would create a for loop that starts at the end of the string (using the string.length() to get this) then output the letters from last to first with system.out.print(namestring.charAt(variable used in for loop));

 

Sorry I couldn't check this right now, but that's how I'd tackle it.

Thanks man. I've got it now.

Current System: CPU - I5-6500 | Motherboard - ASRock H170M-ITX/ac | RAM - Mushkin Blackline 16GB DDR4 @ 2400mHz | GPU - EVGA 1060 3GB | Case - Fractal Design Nano S | Storage - 250GB 850 EVO, 3TB Barracuda | PSU - EVGA 450W 80+ Bronze | Display - AOC 22" 1080p IPS | Cooling - Phanteks PH-TC12DX_BK | Keyboard - Cooler Master QuickFire Rapid(MX Blues) | Mouse - Logitech G602 | Sound - Schiit Stack | Operating System - Windows 10

 

The OG System: I3-2370M @ 2.4 GHz, 750GB 5400 RPM HDD, 8GB RAM @1333Mhz, Lenovo Z580 Laptop (Ubuntu 16.04 LTS).

 

Peripherals: G602, AKG 240, Sennheiser HD 6XX, Audio-Technica 2500, Oneplus 5T, Odroid C2(NAS).

Link to comment
https://linustechtips.com/topic/216692-name-reversal-in-java/#findComment-2970396
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×