From c2741eefd58c19a00642b2e16066ca7c095cb8a7 Mon Sep 17 00:00:00 2001 From: Aditya Kumar Date: Wed, 11 Oct 2023 11:06:46 +0530 Subject: [PATCH] Create ReverseString.java --- Strings/ReverseString.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Strings/ReverseString.java diff --git a/Strings/ReverseString.java b/Strings/ReverseString.java new file mode 100644 index 0000000..5ea70b1 --- /dev/null +++ b/Strings/ReverseString.java @@ -0,0 +1,16 @@ +public class ReverseString { + public static String reverse(String str) { + StringBuilder reversed = new StringBuilder(); + for (int i = str.length() - 1; i >= 0; i--) { + reversed.append(str.charAt(i)); + } + return reversed.toString(); + } + + public static void main(String[] args) { + String original = "Hello, World!"; + String reversed = reverse(original); + System.out.println("Original: " + original); + System.out.println("Reversed: " + reversed); + } +}