Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 03, 2016, 05:56:22 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: java help  (Read 1346 times)

jabborwoc

  • Participant
  • Joined in 2011
  • *
  • Posts: 5
    • View Profile
    • Donate to Member
java help
« on: April 03, 2011, 03:33:05 PM »
Java help open user spec file , count user spec character,
Code: Java [Select]
  1. import java.util.Scanner;
  2. import java.io.*;
  3. public class progChal6
  4.  {
  5.    public static void main(String[] args) throws IOException
  6.    {
  7.      
  8.      //needed for scanner class
  9.       Scanner kb = new Scanner(System.in);
  10.       String filename;   // file name
  11.       int charCount = 0;
  12.      
  13.       // get users filename
  14.       System.out.print("Enter the file name:  ");
  15.       filename = kb.nextLine();
  16.       Scanner inputFile = new Scanner(filename);
  17.       // get users character
  18.       System.out.print("Please enter a character: ");
  19.       char userChar = kb.nextLine().charAt(0);
  20.       // tell the user what the program does
  21.       System.out.println("\n****This program will return how many times" +
  22.                           " the character you entered showed up in" +
  23.                           " the string you entered.****");
  24.                      
  25.       while(inputFile.hasNext()) ;
  26.       {
  27.                (filename.charAt() == userChar);
  28.                   {
  29.                   charCount++;
  30.                   }
  31.       }
  32.       System.out.println("\nThe specified character " +"\"" + userChar +
  33.                           "\" is inside the string " + filename +
  34.                           " " + charCount +   " times.\n");            
  35.     inputFile.close();
  36.     }
  37. }
« Last Edit: April 03, 2011, 04:55:39 PM by mouser, Reason: formatted code »

jabborwoc

  • Participant
  • Joined in 2011
  • *
  • Posts: 5
    • View Profile
    • Donate to Member
Re: java help
« Reply #1 on: April 03, 2011, 04:34:45 PM »
it just needs to count the number of times a specified letter occurs in a specified file :tellme:

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 2,778
    • View Profile
    • Donate to Member
Re: java help
« Reply #2 on: April 04, 2011, 01:23:17 AM »
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

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,406
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: java help
« Reply #3 on: April 04, 2011, 06:24:15 AM »
i think he got it solved in irc.

hamradio

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 677
  • Amateur Radio Guy
    • View Profile
    • HamRadioUSA.net
    • Read more about this member.
    • Donate to Member
Re: java help
« Reply #4 on: April 04, 2011, 01:12:18 PM »
The following url helped him if I remember correctly...

http://www.dreaminco...isplays-wrong-count/
Carroll - HamRadioUSA.net