public void permutations(String data)
{
for( int i =0 ;i < data.length();i++)
{
for(int j=i+1; j<= data.length() ; j++)
{
String subsring = data.substring(i, j);
System.out.println(subsring);
if (subsring.length() > 1)
{
System.out.println(reverse(subsring.toCharArray()));
}
}
}
}
public String reverse(char[] array)
{
int length = array.length;
for (int i =0 ;i < length/2; i++)
{
char temp = array[i];
array[i] = array[length - 1 - i];
array[length - 1 - i] = temp;
}
return new String(array);
}
No comments:
Post a Comment