String Sort Problem ----

What is error in my code--------------
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
String arr[] = new String[n];
for(int i = 0;i<arr.length;i++){
arr[i] = cin.nextLine();
}
for(int i =0;i<arr.length;i++){
for(int j = i+1;j<arr.length-1;i++){
if(arr[i].compareTo(arr[j])>0){
String temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
for(String s: arr){
System.out.println(s);
}
}
}

import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner cin = new Scanner(System.in);
		int n = cin.nextInt();
		String arr[] = new String[n];
		
		for(int i = 0;i<arr.length;i++){
			arr[i] = cin.next();//while taking integer and string as input you should use next() instead of nextLine()
		}

		
		

		for(int i =0;i<arr.length;i++){
			for(int j = i+1;j<arr.length-1;j++){//here the condition in for loop should be j++
				if(arr[i].compareTo(arr[j])>0){//you need to write your own compare function
					String temp = arr[i];
					arr[i] = arr[j];
					arr[j] = temp;
				}
			}
		}

		for(String s: arr){
			System.out.println(s);
		}

	}
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.