This is a simple program called CountVowel. Can this be typed differently?

import java.util.Scanner;
import java.io.*;
public class CountVowels {
     public static void main(String[]args) {
          File textFile;
          FileReader in;
          BufferedReader readFile;
          String fileName;
          String text, letter;
          int vowelsum = 0;
          Scanner input = new Scanner(System.in);     
          System.out.print("Enter the file name: ");
          fileName = input.nextLine();
          try {
               textFile = new File(fileName);
               in = new FileReader(textFile);
               readFile = new BufferedReader(in);
               while ((text = readFile.readLine()) != null) {
                    text = text.toLowerCase();
                    for (int i = 1; i <= text.length(); i++) {
                         letter = text.substring(i-1, i);
                         if (letter.equals("a") || letter.equals("e") || letter.equals("i") || letter.equals("o") || letter.equals("u")) {
                         vowelsum +=1;
               System.out.println("The number of vowels in " + fileName + " is " + vowelsum + ".");
               readFile.close();
              in.close();     
         } catch (FileNotFoundException e) {
               System.out.println("File does not exist or could not be found.");
               System.err.println("FileNotFoundException: " + e.getMessage());
          } catch (IOException e) {
               System.out.println("Problem reading file.");
              System.err.println("IOException: " + e.getMessage());
}

@OP: try using separate methods:
import java.util.Scanner;
import java.io.*;
public class CountVowels {
    private static int count(String lookingFor, String contents) {
        // Scan through 'contents' and check how many time a char from
        // 'lookingFor' is encountered, return that number of occurrences.
        return -1;
    private static String readContents(String fileName) {
        // Read the entire contents of a (text) file and return that as
        // a String.
        return "";
    public static void main(String[]args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the file name: ");
        String fileName = input.nextLine();
        String contents = readContents(fileName);
        int n = count("aeiou", contents);
        System.out.print("The number of vowels in "+fileName+" is "+n+".");
}

Similar Messages

  • Simple program, getting error, can't figure out why

    Hello. I'm new to java and am having some trouble with this simple piece of code. When i compile DisplayObjStatsApplication I get:
    DisplayObjStatsApplication.java [6:1] cannot resolve symbol
    symbol : variable height
    location: class ObjStats
    box1.height = 60;
    ^
    DisplayObjStatsApplication.java [7:1] cannot resolve symbol
    symbol : variable weight
    location: class ObjStats
    box1.weight = 50;
    ^
    DisplayObjStatsApplication.java [8:1] cannot resolve symbol
    symbol : variable depth
    location: class ObjStats
    box1.depth = 20;
    ^
    3 errors
    Errors compiling DisplayObjStatsApplication.
    Here is the code for ObjStats.java:
    public class ObjStats {
    public ObjStats() {
    int height, weight, depth;
    And here is the code for DisplayObjStatsApplication:
    public class DisplayObjStatsApplication {
    public static void main(String[] args) {
    ObjStats box1 = new ObjStats();
    box1.height = 60;
    box1.weight = 50;
    box1.depth = 20;
    What am I doing wrong?
    Thanks

    hi,
    i am new to java too!!!!!!
    maybe you can use some "setter' and "getter" methods!!!!!!!
    Here is the code for ObjStats.java:
    public class ObjStats {
    int height;
    int weight;
    int depth;
    public ObjStats() {
        this.height=0;
        this.weight=0;
        this.depth=0;
    public setHeight(int height) {
       this.height=height;
    public setWeight(int weight) {
       this.weight=weight;
    public setDepth(int depth) {
       this.depth=depth;
    public getHeight() {
       return height;
    public getWeight() {
       return weight;
    public getDepth() {
       return depth;
    And here is the code for DisplayObjStatsApplication:
    public class DisplayObjStatsApplication {
    public static void main(String[] args) {
    ObjStats box1 = new ObjStats();
    box1setHeight(60) ;
    box1.setWeight(50);
    box1.setDepth(20);
    System.out.println("The height of the box is " + box1.getHeight());
    System.out.println("The weight of the box is " + box1.getWeight());
    System.out.println("The depth of the box is " + box1.getDepth());
    }

  • In my dock there was this weird program called "tutorial". While throwing away this program I had to fill in my password. Afterwards I tried to change my password, but my old password doesn't work anymore. Who can help?

    In my dock there was this weird program called "tutorial". While throwing away this program I had to fill in my password. Afterwards I tried to change my password, but my old password doesn't work anymore. Who can help?

    What was this program for, or did you just assume it's something you shouldn't have and therefore arbitrarily decide to "throw it away"? Exactly how did you supposedly throw it away?
    If you didn't change your administrator password, there's no reason it shouldn't work now, so that suggests you did something else, or changed it and then forgot what it was.
    You can't recover that password; you can only change it. To do that, you would need to boot from your Snow Leopard DVD, choose your language, then choose Reset Password from the Utilities menu in the top menu bar.

  • Why can't there be a simple program to setup remote file sharing?

    If someone wants to take a crack at getting my Time Capsule available remotely (off network over internet), I would appreciate it.
    I am a graphic designer and use the other side of my brain. DNS, static IP, MAC address etc is very confusing.
    I purchased a neat little app called Connect360 for Mac that automatically configures music/video sharing to Xbox360 from MacBook Pro. Evrything is automatic. Brilliant. If someone could do that to configure internet file sharing, it would be worth $$$$$$.
    Thanks

    You cannot do a simple program with the multiplicity of internet connections, modem type, ISP types, authentication types. Also you notice that Apple decided everything should now happen from the cloud, so cancelled the mobileme service which did offer easier setup for something that is far more limited, at least for now.
    Also please note there are fridge mechanics who fix fridges and car mechanics who fix cars. Photographers who make a living taking better photos than I can, and computer technicians who do network setups. If you don't fix your car or the washing machine.. why do you need to fix your internet networking?? Pay someone to do it.. but Steve said computers are easy and you got a false impression that everything should just plug together and work.. well it doesn't. Find a tame Computer tech and let him/her carry that part of your business. Spend your time doing what earns you money instead of in frustration at fixing the fridge. (Being symbolic of the computer network).
    It is rather like when I (a computer technician) dabble in graphic design.. I do, and you laugh at the results.. !!
    Please note I no longer work in that field because the pay is miserable, the customers ring up day and night and scream at you that the network is down and it is all your fault, and want you to spend an hour on the phone helping them. No service fee of course. You should on the basis of a single job, help connect their computer to the printer over the phone for an hour, rather than pay you a service call. Since computers are easy and you should just donate your time and life really to helping them do what Steve and Bill said was so easy.

  • How can my client program call program located at server?

    Hi All,
    I have a client-server application. How can my client program call program located at server?
    At the beginning my program works as long as RSA Agentinstalled at client. So my program only call rsa library and communicate with RSA Agentby passing userid and passcode. Once RSA Agent receive it will send to RSA Managers to validate.
    But now my user want the RSA Agent installed in my Server. I wondering how to do that as the library given will only detect local RSA Agent. So I'm thinking to separte the library and create new project. Then in this project as a medium to pass userid and passcode. This project I will compile and allocate to server. Then my programs will call the new program i created by passing userid and passcode. I wondering can I do that?
    Thanks in advance.
    Regards,
    Azli

    Why not take the tutorial first? [http://java.sun.com/javaee/5/docs/tutorial/doc/JavaEETutorial.pdf]

  • My safari browser seems to have been taken over by a malicious program called only-search.  Does any one know how to uninstall this program from safari?  I am running osX 10.10.

    My safari browser seems to have been taken over by a malicious program called only-search.  Does any one know how to uninstall this program from safari?  I am running osX 10.10.

    There is no need to download anything to solve this problem.
    You may have installed the "VSearch" trojan. Remove it as follows.
    Malware is always changing to get around the defenses against it. These instructions are valid as of now, as far as I know. They won't necessarily be valid in the future. Anyone finding this comment a few days or more after it was posted should look for more recent discussions or start a new one.
    Back up all data before proceeding.
    Step 1
    From the Safari menu bar, select
              Safari ▹ Preferences... ▹ Extensions
    Uninstall any extensions you don't know you need, including any that have the word "Spigot," "Trovi," or "Conduit" in the description. If in doubt, uninstall all extensions. Do the equivalent for the Firefox and Chrome browsers, if you use either of those.
    Reset the home page and default search engine in all the browsers, if it was changed.
    Step 2
    Triple-click anywhere in the line below on this page to select it:
    /Library/LaunchAgents/com.vsearch.agent.plist
    Right-click or control-click the line and select
              Services ▹ Reveal in Finder (or just Reveal)
    from the contextual menu.* A folder should open with an item named "com.vsearch.agent.plist" selected. Drag the selected item to the Trash. You may be prompted for your administrator login password.
    Repeat with each of these lines:
    /Library/LaunchDaemons/com.vsearch.daemon.plist
    /Library/LaunchDaemons/com.vsearch.helper.plist
    Restart the computer and empty the Trash. Then delete the following items in the same way:
    /Library/Application Support/VSearch
    /System/Library/Frameworks/VSearch.framework
    ~/Library/Internet Plug-Ins/ConduitNPAPIPlugin.plugin
    Some of these items may be absent, in which case you'll get a message that the file can't be found. Skip that item and go on to the next one.
    The problem may have started when you downloaded and ran an application called "MPlayerX." That's the name of a legitimate free movie player, but the name is also used fraudulently to distribute VSearch. If there is an item with that name in the Applications folder, delete it, and if you wish, replace it with the genuine article from mplayerx.org.
    This trojan is often found on illegal websites that traffic in pirated content such as movies. If you, or anyone else who uses the computer, visit such sites and follow prompts to install software, you can expect more of the same, and worse, to follow.
    You may be wondering why you didn't get a warning from Gatekeeper about installing software from an unknown developer, as you should have. The reason is that the Internet criminal behind VSearch has a codesigning certificate issued by Apple, which causes Gatekeeper to give the installer a pass. Apple could revoke the certificate, but as of this writing has not done so, even though it's aware of the problem. This failure of oversight has compromised both Gatekeeper and the Developer ID program. You can't rely on Gatekeeper alone to protect you from harmful software.
    *If you don't see the contextual menu item, copy the selected text to the Clipboard by pressing the key combination  command-C. In the Finder, select
              Go ▹ Go to Folder...
    from the menu bar and paste into the box that opens by pressing command-V. You won't see what you pasted because a line break is included. Press return.

  • Hello apple I have the problem with my iPhone and my friends have this problem too. My iPhone have the problem about calling and answer the call. When I use my iPhone to call I can't hear anything from my iPhone but the person that I call can answer it bu

    Hello apple
    I have the problem with my iPhone and my friends have this problem too.
    My iPhone have the problem about calling and answer the call. When I use my iPhone to call I can't hear anything from my iPhone but the person that I call can answer it but when answer both of us can't hear anything and when I put my iPhone to my face the screen is still on and when I quit the phone application and open it again it will automatic call my recent call. And when my friends call me my iPhone didn't show anything even the missed call I'm only know that I missed the call from messages from carrier. Please check these problem I restored my iPhone for 4 time now in this week. I lived in Hatyai, Songkhla,Thailand and many people in my city have this problem.
    Who have this problem??

    Apple isnt here. this is a user based forum for technical questions. The solution is to restart, reset, and restore as new which is in the manual after that get it replaced for hard ware failure. if your within your one year warranty its replaced if it is out of the warranty then it is 199$

  • I just bought this iPhone 4S second hand and during incoming and outgoing calls I can't hear the other person talk unless it's on speaker or if I have headphones in. I don't know what to do I've turned up my volume and checked my settings!! Need help

    I Just bought a second hand iPhone 4S I am having issues with the hearing during incoming and outgoing calls, I have turned the volume up and checked my settings but I still have trouble hearing the other person speak. It works if it's on speaker or if I have headphones plugged in. I need help desperately!!!!! Any suggestions on what to do???

    Hey Itsanaasaunders,
    Thanks for the question. I understand that you are experiencing issues hearing sound while on a call (receiver wise, not speakerphone). The following resource provides troubleshooting steps for this symptom:
    If you can't hear a person on a call or voicemail or if the sound quality is poor on iPhone - Apple Support
    http://support.apple.com/en-us/HT203800
    Clear the receiver
    The iPhone receiver won't work properly if it's blocked or dirty. Here's where the receiver is:
    Follow these steps, testing after each:
    - Make sure nothing is blocking the receiver, such as a case or film.
    If you have a new iPhone, remove the plastic film on the front and back of the device.
    - Check the receiver opening to see if it's blocked or dirty. If necessary, clean the receiver opening with a clean, small, dry, soft-bristled brush.
    - While you're on a call, turn on speakerphone. If you still can't hear, then your network or reception could be the issue. Try calling again later or from a different location.
    Restart and update
    1. Restart your iPhone and test again.
    2. If there's still no sound or poor sound quality, update to the latest version of iOS.
    Get more help
    If you've tried these steps and there's still no sound or poor sound quality from your iPhone, contact Apple Support.
    Thanks,
    Matt M.

  • I connect my iphone5s to my 2015 Terrain using Bluetooth, when I make a call I can hear the caller but they can't hear me. Anyone else have this problem? How did you resolve it? Other phones connect and work perfectly.

    NNeed help I connect my iPhone 5s to Bluetooth in my 2015 GMC Terrain. When I make a call i can hear them but they can't hear me. Anyone else have this issue? How did you resolve it. Other phones work fine, just not my phone.

    Hello Sandylynn,
    After reviewing your post, it sounds like you can connect the device with Bluetooth and make and receive calls but they dont hear you. I would recommend that you read this article, it may be able to help the issue.
    If your voice is too faint or sounds unclear using iPhone, or iPod touch - Apple Support
    People can't hear you during a phone
    Thanks for using Apple Support Communities.
    Have a nice day,
    Mario

  • When I try to open a gradebook program called powerschool, I get a message that Java is not deteced, but my computer indicates that it has Java. I can't download any version of Java because I get a message that Apple has its own version of java.  My compu

    When I try to open a gradebook program called powerschool, I get a message that Java is not deteced, but my computer indicates that it has Java. I can't download any version of Java because I get a message that Apple has its own version of java.  My computer indicates that no new software updates are needed.

    Start here: http://support.apple.com/downloads/#java

  • I'm trying to open a 'mv' file.  I found a program called Flip4mac WMV Player Pro.  Does anyone have any experience with this or have another suggestion?

    I am trying open 'mv' files.  I found a program called Flip4mac MWV Player Pro.  Does anyone have experience with this or is there a different way to open these type of files?

    It works quite well, but is only useful for playing .wmv files such as those made on older PCs. MPlayer 1.0 rc2 is a free utility that should also play .wmv files.

  • I'm trying to watch a tv show in my iPad but it keeps freezing 15minutes into the program. How can I fix this?

    I'm trying to watch a tv show on my iPad but it keeps freezing 15 minutes into the program. How can I fix this?

    Moved to Adobe Reader for iOS.
    If you are trying to open an xml based pdf file, then it is not supported on the present version of Reader for iOS.

  • Hi I have a iPhone 4 and I seem to have a problem during calls. If I make or receive a call I can hear the person who is on the line with me but the other person can't hear me. This problem has occurred 1 week ago so please get back thank you

    Hi I have a iPhone 4 and I seem to have a problem during calls. If I make or receive a call I can hear the person who is on the line with me but the other person can't hear me. This problem has occurred 1 week ago so please get back thank you

    You use Restore to get the latest firmware build, not the Update button. You can only use the Update button, if there is an iOS update, say iOS 5.1.
    this link talks about updating to 9A406 to fix the "No Service" issue with iPhone 4S:
    http://iphone-and-i.blogspot.com/2011/12/fixing-iphone-4s-signal-problem.html

  • Hello my company Favorites I would like to first thank you for this wonderful program I have a question about the program. How can I Arabization program In your response to the spread accept me thanks and respect

    Hello my company Favorites I would like to first thank you for this wonderful program I have a question about the program. How can I Arabization program In your response to the spread accept me thanks and respect

    Hi ,
    You might want to refer the following link to find your serial number and activate your software .
    Here is the link for the same.
    https://helpx.adobe.com/x-productkb/global/find-serial-number.html
    Let us know how it goes .We'll do the best possible to get your issue fixed.
    Regards
    Sukrit Dhingra

  • TS3406 i have an i phone 5 when iget a call the caller can here me but i can't here the caller what can i do to rectify this

    hi i have an i phone 5 and when i receive a call the caller can hear me but i can't hear the caller what can i do to rectfiy this?

    When did the issue start?  What (if anything) changed right before it started?

Maybe you are looking for

  • Toshiba Satellite C855D - S5320 Won't charge!

    The topic subject says it all. One day it was working the next it won't boot up. At first I thought my charger crapped out on me, so I ordered a new replacement one from Amazon. When I received it, I plugged it in and it wouldn't charge. So I then th

  • XML validation fails

    Hello, We are trying to validate an XML against a DTD using XDK 9.2.0.5.0 and it fails. The same XML was validated without any problem earlier, but, suddenly started failing with the following error. XML-0201: (Fatal Error) Expected name instead of .

  • Master Agreement Import Failed

    Hi experts, An error was encountered during Data Import of Master Agreement in CLM system.  Logs shown below.   Details of the errors: Failed: object 1: metadata exception Exception: method not found MessageId: exception.common.db.metadata.reflection

  • IInterco STO Return Process

    Hi Experts Clarification on Intercompany STO return order process. To reverse the Intercompany STO, if i use the Return to Vendor through the MIGO, anyway a delivery can be created against this RTV (MIGO) and perform a Goods Reciept ? A flow could be

  • Cannot set date and time

    I am in the UAE and brought over an Apple TV 3rd generation from the US but cannot get it to set the date or time.  This product has not been released yet in this country.