Find Maximum number possible by doing at-most K swaps (Stuck in the problem )

Find Maximum number possible by doing at-most K swaps

Given a positive integer, find the maximum integer possible by doing at-most K swap operations on its digits.

Input: M = 254, K = 1 Output: 524
Swap 5 with 2 so number becomes 524
Input: M = 254, K = 2 Output:
542 Swap 5 with 2 so number becomes 524
Swap 4 with 2 so number becomes 542

public static void main(String[] args) {

    int[] arr= {2,4,5};


public static int MaxNum(int[] arr, int s) {

     int[] strg=new int[arr.length];

	return 0;

	int ans=0;
	for (int k = 1; k <arr.length; k++) {
		strg = swap(arr, k, 0);
	    MaxNum(strg, s-1);
		swap(arr, k, 0);

		for(int val:strg)
			System.out.print(val+".  strg.   ");
	return ans;


public static int[] swap(int[] arr, int a, int b) {

	int temp = arr[a];
	arr[a] = arr[b];
	arr[b] = temp;

	return arr;


I am not sure if my approach is right . Also in above code I am not able to print full array with max number so I have just compared the 0th index (just for now).
How do I print the array with max number? please help

You can just sort the array and then rearrange it so that the largest number comes first and then the second largest number and then accordingly using java.util.Arrays.sort(Object[] a, int fromIndex, int toIndex) , I use C++ so this is equivalent to sort(a,a+n) (where a is the array of size n) and this STL sorts the array in ascending order.
Hope this helps!!

if we sort then how we will take care of K operation. the sorting will give the biggest number possible . can you help me with printing the array after K operations using recursion which I am using above in the code