Last active
February 21, 2018 22:37
-
-
Save lobster1234/5036770 to your computer and use it in GitHub Desktop.
Reverse a String - Scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reverseString(s:String) = (for(i<-s.length-1 to 0 by -1) yield s(i)).mkString | |
//Java Version here: | |
public class Test { | |
public final String reverse(String s) { | |
StringBuffer b = new StringBuffer(s.length()); | |
for(int i = s.length()-1; i >=0; i--){ | |
b.append(s.charAt(i)); | |
} | |
return b.toString(); | |
} | |
public static void main(String[] args) { | |
System.out.println(new Test().reverse("A")); | |
System.out.println(new Test().reverse("Manish")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment