bebelew
02-10-2005, 01:08 AM
I need help finishing this program. What the program is suppose to do is ask the user to input a file and any character they choose. Then the computer is suppose to go through the file and count how many times that character is in the file. This is what I have so far but I need help finishing it.
import java.io.*;
public class SPA4
{
public static void main(String[] args) throws IOException
{
String filename, //File name
line, //To read a line of text
character; //The character
int number = 0, //for number of characters found
location; //for locating the character in the file
// Make the objects necessary for console input
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader keyboard = new BufferedReader(reader);
//Get the filename
System.out.print("Enter the filename: ");
filename = keyboard.readLine();
//Open the file
FileReader freader = new FileReader(filename);
BufferedReader inputFile = new BufferedReader(freader);
//Get the character
System.out.print("Enter the character: ");
character = keyboard.readLine();
//Read the first line in the file
line = inputFile.readLine();
location = line.indexOf(character);
//Close the file
inputFile.close();
//Print the final output
System.out.print(number);
}
}
import java.io.*;
public class SPA4
{
public static void main(String[] args) throws IOException
{
String filename, //File name
line, //To read a line of text
character; //The character
int number = 0, //for number of characters found
location; //for locating the character in the file
// Make the objects necessary for console input
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader keyboard = new BufferedReader(reader);
//Get the filename
System.out.print("Enter the filename: ");
filename = keyboard.readLine();
//Open the file
FileReader freader = new FileReader(filename);
BufferedReader inputFile = new BufferedReader(freader);
//Get the character
System.out.print("Enter the character: ");
character = keyboard.readLine();
//Read the first line in the file
line = inputFile.readLine();
location = line.indexOf(character);
//Close the file
inputFile.close();
//Print the final output
System.out.print(number);
}
}