I'm new to java.. Please help ^^


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: I'm new to java.. Please help ^^

  1. #1
    Join Date
    May 2007
    Posts
    1

    Talking I'm new to java.. Please help ^^

    I got this program from a friend and I would like to know if it could be modified or it could be change in any other way. I just study java for 3 months so I don't really know many methods like others. Thank you =)


    import java.util.Scanner;
    import java.io.*;

    public class CountVowel2 {

    public static void main(String[]args) {

    File txtFile;
    FileReader in;
    BufferedReader readFile;
    String fileName;
    String txt, letter;
    int vowelsum = 0;
    Scanner input = new Scanner(System.in);

    System.out.print("Enter the file name: ");
    fileName = input.nextLine();


    try {
    txtFile = new File(fileName);
    in = new FileReader(txtFile);
    readFile = new BufferedReader(in);
    while ((txt = readFile.readLine()) != null) {
    txt = txt.toLowerCase();
    for (int i = 1; i <= txt.length(); i++) {
    letter = txt.substring(i-1, i);
    if (letter.matches("[aeiou]")) {
    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());
    }
    }
    }

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    In what manner do you want to modify or change it?

Similar Threads

  1. Java book
    By Lou in forum Java
    Replies: 9
    Last Post: 09-19-2007, 05:58 AM
  2. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 06:46 AM
  3. DevX does seem one sideded
    By Rob Abbe in forum Talk to the Editors
    Replies: 44
    Last Post: 01-13-2003, 02:57 PM
  4. Re: VB vs. Visual Age for Java
    By JJ in forum Enterprise
    Replies: 1
    Last Post: 07-06-2000, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center