// Prompt the user for a word, then print it out together with a random 
// permutation of its elements.

import java.util.*;

public class Lab10f05Help
{
    // permute at random the elements of a
    public static void permute(char[] a) {
	int n = a.length;
	for (int j = n; j > 1; j--) {
	    // select at random a position in the range [0,j-1)
	    int k = (int)(Math.random() * j);
	    // swap values at positions k and j-1
	    char temp = a[k];
	    a[k] = a[j-1];
	    a[j-1] = temp;
	}
    }

    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	System.out.print("Enter a word: ");
	String word = sc.nextLine();
	while (word.length() != 0) {
	    char[] cWord = word.toCharArray(); 
	    permute(cWord);
	    System.out.println(word + "\t" + new String(cWord));
	    System.out.print("Enter a word: ");
	    word = sc.nextLine();
	}
    }
}
