Question

Write a Java class which accepts an input argument when the application is executed from the...

Write a Java class which accepts an input argument when the application is executed from the command-line. Add the method reverse(s) which accepts a string as a parameter and returns the string reversed by using the standard charAt() String method.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class ReverseString {

    public static String reverse(String str) {
        String reverseString = "";
        for(int i = str.length()-1; i >= 0; --i) {
            reverseString += str.charAt(i);
        }
        return reverseString;
    }

    public static void main(String[] args) {
        if (args.length == 0) {
            System.out.println("Please provide a string as command line argument");
        } else {
            System.out.println(args[0] + " in reverse is " + reverse(args[0]));
        }
    }

}
Add a comment
Know the answer?
Add Answer to:
Write a Java class which accepts an input argument when the application is executed from the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT