Main Area and Open Discussion > General Software Discussion
java help
(1/1)
jabborwoc:
Java help open user spec file , count user spec character,
--- Code: Java ---import java.util.Scanner;import java.io.*;public class progChal6 { public static void main(String[] args) throws IOException { //needed for scanner class Scanner kb = new Scanner(System.in); String filename; // file name int charCount = 0; // get users filename System.out.print("Enter the file name: "); filename = kb.nextLine(); Scanner inputFile = new Scanner(filename); // get users character System.out.print("Please enter a character: "); char userChar = kb.nextLine().charAt(0); // tell the user what the program does System.out.println("\n****This program will return how many times" + " the character you entered showed up in" + " the string you entered.****"); while(inputFile.hasNext()) ; { (filename.charAt() == userChar); { charCount++; } } System.out.println("\nThe specified character " +"\"" + userChar + "\" is inside the string " + filename + " " + charCount + " times.\n"); inputFile.close(); }}
jabborwoc:
it just needs to count the number of times a specified letter occurs in a specified file :tellme:
Ath:
What's the result you are getting now?
If you added an if before the first bracket on line 27 there would at least be a comparison in the loop.
mouser:
i think he got it solved in irc.
hamradio:
The following url helped him if I remember correctly...
http://www.dreamincode.net/forums/topic/45227-character-counter-displays-wrong-count/
Navigation
[0] Message Index
Go to full version