我的代码不断出现此错误:
“线程主 java.lang.stringindexoutofboundsexception 中的异常字符串索引超出范围”
问题是什么?
import java.util.Scanner;
public class Compress {
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter a string: ");
String compress = scan.nextLine();
int count = 0;
for (count = 0; count <= compress.length(); count++)
{
while( count +1 < compress.length() && compress.charAt(count) == compress.charAt(count + 1))
{
count = count + 1;
}
System.out.print(count + "" + compress.charAt(count));
}
}