Sunday, 18 October 2020

Print all the possible combination.

o p t
o t p
p o t
p t o
t o p
t p o



import java.util.*;
public class combistring
 
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("enter a string");
        String n= sc.nextLine();
        int a = n.length();
       
        for(int i = 0;i<a;i++)
        {
            for(int j = 0;j<a;j++)
            {
            for(int k = 0;k<a;k++)
            {
              if(i!=j&&j!=k&&k!=i)
              {System.out.println(n.charAt(i)+" " +n.charAt(j)+" "+n.charAt(k));
       
                }
            }
        }
    }
  }
}




Output:

enter a string
opt


o p t
o t p
p o t
p t o
t o p
t p o

No comments:

Post a Comment