Strings - String Compression

why is the code showing runtime error ??
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
String a = s.next();
StringBuilder sb = new StringBuilder(a);
compression(sb);
}
public static void compression(StringBuilder s)
{int []count = new int [256] ;
int i ;
StringBuilder D = new StringBuilder();
for (i = 0 ; i<s.length() ; i++)
{count[s.charAt(i)]++;}
for (i = 0 ; i<s.length() ; i++)
{int j = 1;
while (j<=s.length())
{if (s.charAt(i)!=s.charAt(j))
{D.append(s.charAt(i) + count[s.charAt(i)]) ; }
j++;}}
System.out.println(D);}
}

Your code accesses s.charAt(j) even when j == s.length(). That throws RuntimeError. Besides, the logic of your code is wrong. And just a suggestion, please improve your code style . It’s way too dirty.