Recursion-Dictionary Order(Larger)

import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner S=new Scanner(System.in);
String str=S.nextLine();
String str1=str;
DOL(str,"",str);
}
public static void DOL(String str,String ans,String str1)
{
if(str.length()==0)
{
if(ans.compareTo(str1)>0)
System.out.println(ans);
return;
}

	for(int i=0;i<str.length();i++)
	{
		char cc=str.charAt(i);
		String ros=str.substring(0,i)+str.substring(i+1);
		DOL(ros,ans+cc,str1);
	}
}

}

What is wrong in this code?

@Rahul-Kumar-2389849724440887,

Input:
acb
Output:
cab
cba
bac
bca

The order is not lexographic. Use an arraylist so solve this question. Store all the strings in a arraylist. And sort the arraylist and then print your answer

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.