这里是我的代码,我应该读取数据,如AAABBBCCCDDD
和输出a3b3c3d3
。文字未被读入变量
我已经更新了代码,现在代码编译并运行,但是没有输出。我不知道它是如何读取数据或代码是不正确的。
String text;
FileReader data = new FileReader("input.txt");
BufferedReader in = new BufferedReader(data);
text=in.readLine();
in.close();
//Counter looks at length of data
int counter=0;
//Counter2 looks at current letter or number to make see if its the same then iterates it
int counter2=0;
while (text.charAt(counter)<=text.length())
{
while (text.charAt(counter)==text.charAt(counter2+1))
{
counter2++;
}
System.out.println(text.charAt(counter) + counter2);
counter=counter2;
}
你的天堂”告诉我们编译错误。 –
请注意,您有两个密切的投票,因为您没有显示任何错误消息。 –
我刚刚更新了一切,因为其他人的帮助显示了代码中的一个基本缺陷。 – user3339579