Skip to content

Instantly share code, notes, and snippets.

@SandeepGamot
Last active September 21, 2017 17:53
Show Gist options
  • Save SandeepGamot/f1c33da8fd1e3c55926ba79d73ce4341 to your computer and use it in GitHub Desktop.
Save SandeepGamot/f1c33da8fd1e3c55926ba79d73ce4341 to your computer and use it in GitHub Desktop.
This is a Code Snippet to reverse elements of an Array of any data type. This code snippet is applied to a custom hashing algorithm.
// free for commercial and personal use.
// User can modify and redistribute,include author credits.
// @author: Sandeep Gamot
// Github/Sandeep Gamot
import java.util.Scanner;
import java.lang.StringBuffer;
class Methods extends StringHash
{
String [] getArray(int n) //takes a num and gives an String arr of size num
{
String []arr = new String[n];
for(int i=0; i<n; i++)
{
arr[i]=sc.next();
}
return arr;
}
void traverseArray(String[] arr) //traverses array and passes elements to reverseFn()
{
for(int i=0; i<arr.length; i++)
{
reverseFn(arr[i]);
System.out.print("\t");
}
}
void reverseFn(String st)//applying Stringbuffer functions to reverse
{
String reverse = new StringBuffer(st).reverse().toString();
System.out.print(reverse);
}
}
class StringHash
{
static Scanner sc = new Scanner(System.in);
public static void main(String args[])
{
int arraySize = sc.nextInt();
Methods obj = new Methods();
obj.traverseArray(obj.getArray(arraySize));
}
}
@SandeepGamot
Copy link
Author

SandeepGamot commented Sep 20, 2017

If you are reading this....and if you are a Java Ninja.
Review and teach me better java.
My Master!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment