I am reading a file from the user and now I have to count the number of characters, blank spaces, digits, "other characters", words, and lines in a text file using a loop.
I am having trouble considering what methods of class Character to use and how to increment a counter for each type of character inside a loop.
Here is what I have thus far: *I only have the basic beginning*
import java.util.*; import java.io.*; public class Reader { public static void main (String args[]) throws IOException { Scanner console = new Scanner(System.in); String filename; String last; //Declared FileReader and Scanner for the user System.out.println("Please enter the name of the file to be read. "); filename = console.nextLine(); FileReader inputFile = new FileReader(filename); Scanner input = new Scanner(inputFile); // Loops to count number of characters, etc. while (input.hasNextLine()) { last = input.nextLine(); System.out.println(last); } } }
I have created another program before hand to decide the characters, but I don't know if I could increment this into my main.
if (asciiValue >= 49 && asciiValue <= 57) System.out.println("Input is a number"); else if (asciiValue >= 65 && asciiValue <= 90) System.out.println("Input is an uppercase letter"); else if (asciiValue >= 97 && asciiValue <= 122) System.out.println("Input is a lowercase letter"); else if (asciiValue == 32) System.out.println("Input is a space"); else System.out.println("Input is an other character");