Twistid
5,000+ posts
150.5
import java.io.*;
public class IOLoop
{
public static BufferedReader inFile;
public static PrintWriter outFile;
public static void main(String[] args) throws IOException
{
int lineCount = 0;
int blankCount;
int index;
String inputString;
inFile = new BufferedReader(new FileReader("history.dat"));
outFile = new PrintWriter(new FileWriter("data.out"));
inputString = inFile.readLine();
while (inputString != null)
{
lineCount++;
blankCount = 0;
index = inputString.indexOf(' ');
while (index != -1)
{
blankCount++;
if (inputString.length() != 1)
{
inputString = inputString.substring(index+1,
inputString.length());
index = inputString.indexOf(' ');
}
else index = -1;
}
outFile.println("Line " + lineCount + " contains "
+ blankCount + " blanks.");
inputString = inFile.readLine();
}
outFile.close();
inFile.close();
}
}
i need to edit this to count words instead of blank's , it sounds easy but its really kickin me in the butt, any help would be apprecaited
public class IOLoop
{
public static BufferedReader inFile;
public static PrintWriter outFile;
public static void main(String[] args) throws IOException
{
int lineCount = 0;
int blankCount;
int index;
String inputString;
inFile = new BufferedReader(new FileReader("history.dat"));
outFile = new PrintWriter(new FileWriter("data.out"));
inputString = inFile.readLine();
while (inputString != null)
{
lineCount++;
blankCount = 0;
index = inputString.indexOf(' ');
while (index != -1)
{
blankCount++;
if (inputString.length() != 1)
{
inputString = inputString.substring(index+1,
inputString.length());
index = inputString.indexOf(' ');
}
else index = -1;
}
outFile.println("Line " + lineCount + " contains "
+ blankCount + " blanks.");
inputString = inFile.readLine();
}
outFile.close();
inFile.close();
}
}
i need to edit this to count words instead of blank's , it sounds easy but its really kickin me in the butt, any help would be apprecaited