我需要一个JTextArea在行的末尾它计算在该行中的字符 [英] I need a JTextArea that at the end of a row it counts characters in that row
问题描述
我需要一个 JTextArea
,它接受一个文本文档的票,只是'y'和'n',使用 BufferedReader
由我的教授给我;它需要计算第一行和后面的每一行的'y'和'n'字符。他给了类提示数组将是有用的,但我不知道如何这样做,任何帮助将非常感谢。谢谢!
I need to make a JTextArea
that takes in a text document of votes, which are just 'y' and 'n', using a BufferedReader
given to me by my professor; and it needs to count the 'y' and 'n' characters within that first row and for each row after. He gave the class a hint that an array would be useful, but I'm not sure how to do this and any help would be greatly appreciated. Thanks!
编辑:这不是一个家庭作业,但我需要知道如何做这个今晚,所以我可以实际上能够实现它为我的最后
This is not really a homework assignment, but I need to know how to do this by tonight so I can actually be able to implement it for my final, which is tomorrow.
推荐答案
您可以在文章 如何使用文字区域 。
You'll find suitable examples in the article How to Use Text Areas.
附录:一个周到的观察者问,
Addendum: A thoughtful observer asks,
在单行中获取文本的代码是什么?
What would be the code to get the text in a single row?
BufferedReader
可能是不错的选择,如本示例中所建议,复制 stdin
至 stdout
:
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String s;
while ((s = in.readLine()) != null) {
// process s
}
这篇关于我需要一个JTextArea在行的末尾它计算在该行中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!