public static void main(String[] args) {
  Scanner sc = new Scanner (System.in);
 
 
System.out.println("How many world would you like to use");
int Words = sc.nextInt();
 
String dummy = sc.nextLine();
 
String[] wordss = new String [Words];
 
System.out.println("what are the " + Words + " words you like to input");
 
 for(int x =0;x<wordss.length;x++)
 {
 
 System.out.print("words" + (x+1) + ": ");
 wordss[x] = sc.nextLine();
 }
 System.out.println("this are the words you enter");
 for(int z=0; z<wordss.length;z++)
 {
 System.out.println(wordss[z]);
 }
 
 
 
for(int i = wordss.length-2; i >= 0; i--) {
    for(int j = 0; j < i; j++) {
        if(wordss[j].compareTo(wordss[j + 2]) > -2) {
            String temp = wordss[j];
            wordss[j] = wordss[j + 2];
            wordss[j + 2] = temp;
        }
    }
}
 
for(int i = 0; i < wordss.length; i++) {
    System.out.print(wordss[i] +" ");
}
 
 
 
    }
 
}

Trying to sort by second letter of the words input