Couldn't pass my test case even my ans is correct for different different input tell me where I'm wrong....?

package Assignment;

import java.util.Scanner;
public class Largestnofromgivenarray {

public static void main(String[] args) {
       Scanner sc = new Scanner (System.in);
	   int tc=sc.nextInt();
	   int[] arr= null;
	   String ab ="";
	   String ba="";
	   String ans =""; 
	   for(int row=1;row<=tc;row++) {
		   int nv=sc.nextInt();
		   arr =new int[nv];
		   for(int col=0;col<nv;col++) {
			   arr[col]=sc.nextInt();
		   }
		   for(int i=0;i<nv-1;i++) {
			   for(int col=i+1;col<nv;col++) {
				  ab=(String.valueOf(arr[i])+String.valueOf(arr[col]));
				  ba=(String.valueOf(arr[col])+String.valueOf(arr[i]));
				  if(Integer.valueOf(ab)>Integer.valueOf(ba)) {
					  col=col+1-1;
				  }else {
					  int temp=arr[col];
					  arr[col]=arr[i];
					  arr[i]=temp;
				  }
				
			   }

@Jai_hind,
Please check your previous doubt. I have responded there.

import java.util.*; public class Main { public static void main(String args[]) { Scanner sc = new Scanner (System.in); int tc=sc.nextInt(); int[] arr= null; String ab =""; String ba=""; for(int row=1;row<=tc;row++) { int nv=sc.nextInt(); String ans =""; arr =new int[nv]; for(int col=0;col<nv;col++) { arr[col]=sc.nextInt(); } for(int i=0;i<nv-1;i++) { for(int col=i+1;col<nv;col++) { ab=(String.valueOf(arr[i])+String.valueOf(arr[col])); ba=(String.valueOf(arr[col])+String.valueOf(arr[i])); if(Integer.valueOf(ab)>Integer.valueOf(ba)) { col=col+1-1; }else { int temp=arr[col]; arr[col]=arr[i]; arr[i]=temp; } } } for(int i=0;i<arr.length;i++) { ans+=String.valueOf(arr[i]); } System.out.println(ans); } } }

sir after initialize ans variable under for loop my testcase 0 is passed but all other tc is still failed…

@ sanchit.bansal06 sir after initialize ans variable under for loop my testcase 0 is passed but all other tc is still failed…

@Jai_hind,
I am checking wait

1 Like

ok sir…

@Jai_hind,
https://ide.codingblocks.com/s/416935 corrected code.
Error in line 20. I have corrected the mistake.

Use Long.valueOf instead of Integer.valueOf

1 Like

Thank you so much sir I had been stuck in this problem from 2 days…finally it solved with your help… :heavy_heart_exclamation:

@sanchit.bansal06 I have marked as resolved…