public static void main(String[] args) throws IOException {
Scanner in = new Scanner(new FileReader( "/input5.txt"));
input5.txt — это текстовый файл, из которого я читаю ввод.
BufferedReader is = new BufferedReader(new FileReader "/input5.txt"));
int wordcount = 0;//counter
int i = 0;//each character of input
boolean hasChar = true;//flag for has Character
while (in.hasNextLine()) { // while input exists
String a = in.nextLine();//get next line
while (i < a.length()) {// get each char
if (a.charAt(i) == ' ') {// blank space does not count in word count
hasChar = false;
}// does not work
else {
wordcount++;// count words
}
i++;//get each char
}
}
System.out.println("The word count is " + wordcount);// print wordcount
System.out.println("");
String line;// echo print the input file
while ((line = is.readLine()) != null) {
System.out.println("Echo print of the file: " + line);
}
in.close();
}
Это мой код.
Входной файл включает в себя это
Айвегфу24р;q0912j
129puehilhwueildgyuol
Вторая строка кода не учитывается при подсчете слов. Как я могу исправить это только с помощью циклов while?
Пожалуйста, не давайте мне ответ, а направляйте меня.