Form Biggest number(getting wrong answer)

import java.util.*;

public class Biggest_no {

public static void main(String args[])
{
	Scanner scn = new Scanner(System.in);
	
	int t = scn.nextInt();
	while(t-->0)
	{
		int n = scn.nextInt();
		
		int arr[]=new int[n];
		
		for(int i=0;i<n;i++)
		{
			arr[i]=scn.nextInt();
		}
		
		sort(arr);	
		
		display(arr);
	}}
	
public static void display(int arr[])
{
	for(int val:arr)
	{
		System.out.print(val);
	}
}
	public static void sort(int arr[])
	{
		for(int i=0;i<arr.length;i++)
		{
			for(int j=i+1;j<arr.length;j++)
			{
				if(compare(arr[i],arr[j])>0)
				{
					int temp = arr[i];
					arr[i]=arr[j];
					 arr[j]=temp;
				}
			}
		}
	}
	
	public static int compare(int a,int b)
	{
		String s1 = a+""+b;
		String s2 = b+""+a;
		
		int v1 = Integer.valueOf(s1);
		int v2 = Integer.valueOf(s2);
		
		if(v1>v2)
			return -1;
		else
			return 1;
	}

}

Your code runs perfectly. Just print the results in different lines according to the reqd output.
Just a silly error! xD

1 Like

Also, don’t forget to mark the reviews. I’ll always be there to help you out

1 Like