I have a program which prints the all the possibilities of permutations for a given string. But it is static, I hard coded 3 for loops, assuming that the string will be of length 3. But if I have to make it dynamic, the user may enter input a string of length 5. So what I'm asking is if I can inject for loops as per the input of the user?
import java.util.*;
import java.lang.*;
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
String input = "abc";
int i=0,j=0,k=0;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
for(k=0;k<3;k++){
System.out.println(input.charAt(i)+""+input.charAt(j)+""+input.charAt(k));
}
}
}
}
}