Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package down0310_l02;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- public class Lab02 {
- public static void main(String[] args) {
- try {
- File file = new File("pelee.txt");
- Scanner fileScanner = new Scanner(file);
- Scanner lineScanner = null;
- Scanner wordScanner = null;
- String line = "";
- String word;
- String clean_word;
- int line_count = 0;
- int word_count = 0;
- int number_count = 0;
- while (fileScanner.hasNextLine()) {
- line = fileScanner.nextLine();
- lineScanner = new Scanner(line);
- while(lineScanner.hasNext()){
- if (lineScanner.hasNextInt()) {
- word = lineScanner.next();
- clean_word = "";
- for (int i = 0; i < word.length();i++){
- if (word.charAt(i)!=','){
- clean_word += word.charAt(i);
- }
- }
- Integer num = Integer.valueOf(clean_word);
- System.out.println("-----------------");
- System.out.println(num);
- System.out.println("-----------------");
- number_count++;
- }
- else {
- word = lineScanner.next();
- }
- word_count++;
- }
- lineScanner.close();
- line_count++;
- }
- System.out.println("Line Count: " + line_count);
- System.out.println("Word Count: " + word_count);
- System.out.println("Average Number of Words per Line: " + word_count/line_count );
- System.out.println("Number Count: " + number_count);
- fileScanner.close();
- // Print the results
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement