Could you write me a program that counts number of words in
Could you write me a program that counts number of words in file, but only words bigger than 6. JAVA
Solution
D://inputfile1.txt (Save this file under D Drive.Then the path of th efile pointing to it is D://inputfile1.txt )
A computer is a device that can be instructed to carry out an
 arbitrary set of arithmetic or logical operations automatically.
 The ability of computers to follow a sequence of operations
 called a program make computers very flexible and useful.
 Since ancient times simple manual devices like the abacus
 aided people in doing calculations. Early in the Industrial
 Revolution, some mechanical devices were built to automate
 long tedious tasks, such as guiding patterns for looms.
______________________________
CountingNoOfWordsInFileGt6.java
import java.io.File;
 import java.io.IOException;
 import java.util.Scanner;
 public class CountingNoOfWordsInFileGt6 {
 public static void main(String args[]) {
 // Declaring variables
 int no_of_words=0,count_words=0 ;
   
 //Assigning the file name to the String variable
 String fname = \"D://inputfile1.txt\";
//Creating the Scanner class reference
 Scanner sc=null;
 String line=null;
 String words[];
   
 try{
 //Opening the file
 sc= new Scanner(new File(fname));
   
 //This loops continue to execute until the end of the file
 while (sc.hasNext()){
   
 
 line=sc.nextLine();
   
 
 //splitting each line into String array
 words=line.split(\" \");
 for(int j=0;j<words.length;j++)
 {
 no_of_words++;
    if(words[j].length()>6)
    {
 //Counting no of words in the file whose length is greater than 6
 count_words++;
    }
 }
 // count_words+=new StringTokenizer(line,\" ,\").countTokens();
 }
 } catch (IOException e)
 {
 //Displaying the exception
 System.out.println(\"Exception :\"+e);
 }
   
 //Displaying the number of words in the file
 System.out.println(\"Total No of Words in the File :\"+no_of_words);
   
 //Displaying the number of words in the file whose length is greater than 6
 System.out.println(\"No of Words in the File whose length is greater than 6 :\"+count_words);
   
 
 }
 }
_______________________________
Output:
Total No of Words in the File :75
 No of Words in the File whose length is greater than 6 :26
____________ThankYou


