Hi guys, Just wondering if someone could help point out why the string value s1 in the for loop cannot be passed on to String input....
here is my code.
Please ignore the commented out parts. Cheers for any help
import java.io.*;
import java.util.*;
import java.lang.*;
public class gaelan3
{
static int size;
static int count;
static char[] charArray;
public static void main(String[] args) throws IOException
{
/*System.out.println("Please enter letters for anagram problem to be solved. Thankyou");
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
String s = read.readLine();
String input = s;
*/
String validChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Random r = new Random();
for(int i=1; i<10; i++)
{ char randomChar = validChars.charAt(r.nextInt(validChars.length()));
String s1 = Character.toString(randomChar);
//System.out.println(s1);
}
String input = s1;
size = input.length();
count = 0;
charArray = new char[size];
for (int j = 0; j < size; j++)
charArray[j] = input.charAt(j);
doAnagram(size);
}
public static void doAnagram(int newSize)
{
int limit;
if (newSize == 1) // if too small, return;
return;
// for each position,
for (int i = 0; i < newSize; i++) {
doAnagram(newSize - 1); // anagram remaining
if (newSize == 2) // if innermost,
display();
rotate(newSize); // rotate word
}
}
// rotate left all chars from position to end
public static void rotate(int newSize)
{
int i;
int position = size - newSize;
// save first letter
char temp = charArray[position];
//shift others left
for (i = position + 1; i < size; i++)
charArray[i - 1] = charArray[i];
//put first on right
charArray[i - 1] = temp;
}
public static void display()
{
System.out.print(++count + " ");
for (int i = 0; i < size; i++)
System.out.print(charArray[i]);
System.out.println();
}
}