This code is not incuding last element.Can you plz check it and edit?!

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int N=sc.nextInt();
String[] name =new String[N];
for(int i=0;i<N;i++){
name[i]=sc.nextLine();
}
for(int i=0;i<N-1;i++){
for(int j=i+1;j<N;j++){
String temp=name[i];
name[i]=name[j];
name[j]=temp;

		}
	}
	for(int i=0;i<N;i++){
		System.out.println(name[i]);
	}
}

}

Hey @Rajput.apry
Sort all the strings ( lexicographically ) but if a string is present completely as a prefix in another string, then string with longer length should come first.