Q:

Java Program to reverse a string entered by user

0

Java Program to reverse a string entered by user using for loop

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;
public class demo1 {

    public static void main(String[] args) {
        String str;
        System.out.println("Enter your username: ");
        Scanner file = new Scanner(System.in);
        str = file.nextLine();
        file.close();
        String reverse = reverseString(str);
        System.out.println("The reverse string is: " + reverse);
    }

    public static String reverseString(String str)
    {
        if (str.isEmpty())
            return str;
        return reverseString(str.substring(1)) + str.charAt(0);
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now