Tring string compression (only two test cases are correct out of 4)

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String s = sc.next();
int count = 1;
for(int i = 0;i<s.length()-1; i++){
if(s.charAt(i) == s.charAt(i+1)){
count++;
}
else{
System.out.print(s.charAt(i));
if(count>1)
System.out.print(count);
count = 1;
}
}
if(s.charAt(s.length()-1)!= s.charAt(s.length()-2)){
System.out.print(s.charAt(s.length()-1));
}

}

}

HI , Your code will stop working when there is string of only one character as the else loop will never hit. ex- aaa will give no output