I'm trying to create a program that reads a text file and count the number of alphabetic words in the file. I can't get my program to read just the alphabetic words. Here is my program import java.util.*; import java.io.*;
Need help with java program?
4
I'm trying to create a program that reads a text file and count the number of alphabetic words in the file. I can't get my program to read just the alphabetic words. Here is my program
import java.util.*;
import java.io.*;
public class MyFileContents7 {
public static void main (String[] args) throws IOException{
BufferedReader reader = new BufferedReader(new FileReader("address.txt"));
int lines = 0;
int words = 0;
while (reader.readLine() != null){
lines++;
}
File file = new File("address.txt");
Scanner sc = new Scanner(new FileInputStream(file));
int count=0;
while(sc.hasNext()){
sc.next();
count++;
}
System.out.println("Number of words: " + count);
System.out.println(lines);
reader.close();
}
}
import java.util.*;
import java.io.*;
public class MyFileContents7 {
public static void main (String[] args) throws IOException{
BufferedReader reader = new BufferedReader(new FileReader("address.txt"));
int lines = 0;
int words = 0;
while (reader.readLine() != null){
lines++;
}
File file = new File("address.txt");
Scanner sc = new Scanner(new FileInputStream(file));
int count=0;
while(sc.hasNext()){
sc.next();
count++;
}
System.out.println("Number of words: " + count);
System.out.println(lines);
reader.close();
}
}
- Valdor Kiebach
- [1] reply
- bugtrack
- Prrmod
Next Topics on Trending Feed
-
4