Answer:
// Program is written in Java Programming Language
// Comments are used for explanatory purpose
import java.util.*;
public class Perm {
/* function to check whether a strings is a permutation of the other */
static boolean arePermutation(String shortStr, String longStr)
{
// Get lenghts of both strings
int n1 = shortStr.length();
int n2 = longStr.length();
int pos; // Permutation Position
char ch1[] = shortStr.toCharArray();
char ch2[] = longStr.toCharArray();
// Sort both strings
Arrays.sort(ch1);
Arrays.sort(ch2);
// Compare sorted strings
for (int i = 0; i < n1; i++)
if (ch1[i] != ch2[i])
return false;
else
pos = i;
return true;
}
// Program Main Method
public static void main(String[] args)
{
String shortStr, longStr; int pos;
Scanner input = new Scanner(System.in);
System.out.print("Enter any two strings");
shortStr = input.nextLine();
longStr = input.nextLine();
if (arePermutation(shortStr, longStr)
System.out.println("Yes");
else
System.out.println("No");
}
}