String Sort(no such element exception)

//package geeksforgeek1;

import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

public class SortString {

public static void main(String[] args) {

	Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
 TreeSet<String> set=new TreeSet<>();
 String s[]=new String[n];	
 for(int i=0;i<n;i++)
     {
	 s[i]=sc.next();
	   }
	Arrays.sort(s);

	System.out.println();
	for(int i=0;i<s.length;i++)
	{
		if((i+1)<n&&s[i+1].length()>s[i].length())
		{
			System.out.println(s[i+1]);
			System.out.println(s[i]);
	       i++;
		}
		else
		{
			System.out.println(s[i]);
		}
		
	}
	
	
	
	
}

}
it is giving no such element exception even it is running correctly on eclipse

Please post the link to the question so that I can help you properly.
And instead of copying the code directly here, please save it on the ide, https://ide.codingblocks.com/
and then share that link here, as it is easier to debug and find mistakes.

A common mistake that students usually do
You need to write
scn.nextLine();
when you are taking input of string just after an integer

like
int t = scn.nextInt();
scn.nextLine();
String s = scn.nextLine();

This is required because when you press enter after the integer, the ā€œ\nā€, character gets stored in the buffer and is considered as String s, if the line scn.nextLine(); is not mentioned.
Writing scn.nextLine(); this consumes the ā€œ\nā€ character and the string entered goes to s, as is required.