Skip to content

Conversation

@ABHIRANJAN-KUMAR1
Copy link

Java Program: Reverse a String

This PR adds a beginner-friendly Java program ReverseString.java that reverses any string entered by the user. The program uses a reusable function with StringBuilder and includes detailed comments explaining how each part works. This makes it easy for beginners to understand the logic and learn good coding practices.

Features

  • Reads input from the user using Scanner.
  • Reverses the string using a reusable function.
  • Prints the reversed string to the console.
  • Includes step-by-step comments in the code.
  • Provides example input and output for clarity.

How It Works

  1. The program prompts the user to enter a string.
  2. The input string is passed to the reverseString function.
  3. Inside the function, StringBuilder is used to reverse the string.
  4. The reversed string is returned and printed.
  5. The program closes the Scanner to free resources.

Example Usage

Example 1:

Input:
Enter a string to reverse: Hello World

Output:
Reversed string: dlroW olleH

Example 2:

Input:
Enter a string to reverse: Hacktoberfest

Output:
Reversed string: tsefrebotkcaH

This program reverses a user-input string using StringBuilder.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant