Test case failed

Scanner sc = new Scanner(System.in);
int n = 0;
if (sc.hasNext()) {
n = sc.nextInt();
}

	String[] a = new String[n];
	for (int i = 0; i < n; i++) {
		a[i] = sc.next();
	}
	for (int i = 0; i < n - 1; i++) {
		for (int j = 0; j < n - 1 - i; j++) {
			if (a[j].charAt(0) == a[j + 1].charAt(0)) {
				if (a[j + 1].length() > a[j].length()) {
					String temp = a[j + 1];
					a[j + 1] = a[j];
					a[j] = temp;
				}
			} else if (a[j + 1].compareTo(a[j]) < 0) {
				String temp = a[j + 1];
				a[j + 1] = a[j];
				a[j] = temp;
			}
		}
	}
	for (String s : a) {
		System.out.println(s);
	}

please share your complete code by saving it on ide.codingblocks.com so that its legible