我刚刚得到了一些家庭作业,让我做这个奇怪的任务。老师希望我们将各种句子分解成单词。老师已将这些文件放入通过扫描仪导入的文件中。如何将字符串拆分为字符而不使用拆分方法或使用数组?
老师要我们然后用这句话,来计算长度,单词的数量应与词的数量沿着循环的每个迭代增加。
文件总是以“#”字符结束,因此这正是我开始。
这里是我迄今为止现在
class Assignmentfive
{
private static final String String = null;
public static void main(String[] args) throws FileNotFoundException
{
Scanner scan = new Scanner(new File("asgn5data.txt"));
String fileRead = " ";
System.out.print(fileRead);
double educationLevel = 0;
double wordCount = 0;
while (fileRead != "#")
{
fileRead = scan.nextLine();
int firstIndex = fileRead.indexOf(" ");
String strA = fileRead.substring(0,firstIndex);
System.out.print(strA);
int strLength = strA.length();
wordCount++;
}
,有更多的底部,也就是我的计算,我无法弄清楚如何从文件
任意抽取一个字一个字提示?
Thanks``
你在正确的轨道上。你只需要用'fileRead'来做更多的事情。在找到一行中的第一个单词后,您需要在同一行中检查更多内容。 – Cruncher
'FILEREAD = “#”' - > [?我如何在Java中比较字符串(http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Pshemo