Last active
September 21, 2017 17:53
-
-
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.
This file contains 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
// 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)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you are reading this....and if you are a Java Ninja.
Review and teach me better java.
My Master!