DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: java help  (Read 4,151 times)

jabborwoc

  • Participant
  • Joined in 2011
  • *
  • Posts: 5
java help
« on: April 03, 2011, 08:33 PM »
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();
    }
}
« Last Edit: April 03, 2011, 09:55 PM by mouser »

jabborwoc

  • Participant
  • Joined in 2011
  • *
  • Posts: 5
Re: java help
« Reply #1 on: April 03, 2011, 09:34 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: 3,649
    • Participated in NANY Challenge Eleven Times
    • Coding Snacks
    • Linux User
    • Hardware Hacker
Re: java help
« Reply #2 on: April 04, 2011, 06:23 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.
/Ton
Ath's software collection, Quote: "A problem well stated is a problem half-solved." (Charles Kettering)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: java help
« Reply #3 on: April 04, 2011, 11:24 AM »
i think he got it solved in irc.

hamradio

  • Amateur Radio Guy
  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 893
    • Plugin Coding Medal
    • Participated in NANY Challenge Fifteen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
    • Hardware Hacker
Re: java help
« Reply #4 on: April 04, 2011, 06:12 PM »
The following url helped him if I remember correctly...

http://www.dreamincode.net/forums/topic/45227-character-counter-displays-wrong-count/

Original address: https://www.donationcoder.com/forum/index.php?topic=26289.0