import java.util.*;
import java.lang.*;
import java.io.*;
class wordOccur
{
public static void main(String[] a)throws Exception
{
int i;
int[]f=new int[20];
System.out.println("Enter the Sequence of the String:");
Scanner s=new Scanner(System.in);
for(i=0;i<f.length;i++)
f[i]=0;
String t=s.nextLine();
count(t);
}
static void count(String t)
{
int[] f=new int[14];
int i;
String d=" ";
String[] temp=t.split(d);
for(i=0;i<temp.length;i++)
{
System.out.println(temp[i]);
int l=temp[i].length();
f[l]++;
}
for(i=1;i<f.length;i++)
System.out.println(+ i +" "+f[i]+" ");
}
}
How to input a file (words.txt) and print to the screen a table indicating how many one-letter words, two-letter words, three-letter words, etc...
For example:File: This is a test for a java program.
output
1 2
2 1
3 1
4 3
5 0
6 0
7 1
stopping with the longest word and ignoring characters like ?!$#% these
If someone could explain or fix my code that would be great! thanks