Where to Use the String?

In which function should i use the string?
I am not getitng that.

It will be better if you can modify the code and let me know.

Thanks

Hey @kavit The code is given below after modification the changes that I have made is :
i) Using String to store answer in display function.
ii)Using long instead of int in the compare Function val1int and val2int Variables.

import java.util.*;
public class Main {
   public static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);

        int tc = scn.nextInt();

        while (tc > 0) {
            int n = scn.nextInt();

            int[] arr = new int[n];

            for (int i = 0; i < arr.length; i++) {
                arr[i] = scn.nextInt();
            }

            sort(arr);

            display(arr);
            tc--;
        }
    }

    public static void display(int[] arr) {
		String ans = "";
        for (int val : arr) {
            ans += val;
        }

        System.out.println(ans);
    }

    public static int[] takeInput() {
        int len = scan.nextInt();
        int[] arr = new int[len];
        for (int i = 0; i < len; i++) {
            arr[i] = scan.nextInt();
        }
        return arr;
    }

    public static void sort(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - i - 1; j++) {
                if (compare(arr[j], arr[j + 1]) > 0) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }

    public static int compare(int n1, int n2) {
        String val1 = n1 + "" + n2;
        String val2 = n2 + "" + n1;

        long val1int = Long.valueOf(val1);
        long val2int = Long.valueOf(val2);

        if (val1int > val2int)
            return -1;
        else
            return 1;
    }

}

this issue has been resolved, but i hhave 1 ques: &gt is used at many places by you, please tell it’s meaning

Hey @kavit I cannot see any use of word “&gt” Specify the sentence you are emphasizing.

in the solution that you have provided, you have used &gt :in if statement.
This is first time i have seen it in java

@kavit If statements that I have used are :
i)
if (compare(arr[j], arr[j + 1]) > 0) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}

ii) if (val1int > val2int)
return -1;
else
return 1;
And there is no use of &gt like keyword. So you should see the replies in Laptop instead of mobile if that solves the problem.

I just compare the previous reply on mobile and laptop.
On mobile it is fine, but on laptop it is also fine on discussion form link but in doubt section ,it is &gt.

Some issue, may be with laptop.

Btw, you can mark it as resolved.

Thanks bro

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.