Skip to content

Instantly share code, notes, and snippets.

Created September 11, 2017 09:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Anagram class for a tutorial on the SSaurel's Blog
package com.ssaurel.anagram;
import java.util.Random;
* Created by ssaurel on 05/09/2017.
public class Anagram {
public static final Random RANDOM = new Random();
public static final String[] WORDS = {"ACCOUNT", "ADDITION",
public static String randomWord() {
return WORDS[RANDOM.nextInt(WORDS.length)];
public static String shuffleWord(String word) {
if (word != null && !"".equals(word)) {
char a[] = word.toCharArray();
for (int i = 0; i < a.length; i++) {
int j = RANDOM.nextInt(a.length);
char tmp = a[i];
a[i] = a[j];
a[j] = tmp;
return new String(a);
return word;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment