diff --git a/week1/day2/classroom/string/ReverseString.java b/week1/day2/classroom/string/ReverseString.java index 700e920..ce47867 100644 --- a/week1/day2/classroom/string/ReverseString.java +++ b/week1/day2/classroom/string/ReverseString.java @@ -4,25 +4,12 @@ public class ReverseString { public static void main(String[] args) { - // Here is the input String test = "feeling good"; - - // Build the logic to find the count of each - /* Pseudo Code: 1 - a) Convert the String to character array - b) Traverse through each character (using loop in reverse direction) - c) Print the character (without newline -> like below - System.out.print(ch); - */ - - - - /* Pseudo Code: 2 - a) Find the length of the string - b) Traverse through each index from length-1 -> 0 (using loop in reverse direction) - c) Find the character of the String using its index - */ + char[] charArray = test.toCharArray(); + int length = test.length(); + for (int i = length-1; i >=0; i--) { + System.out.println(charArray[i]); } -} \ No newline at end of file +}