• Post Reply Bookmark Topic Watch Topic
  • New Topic

regarding files  RSS feed

 
Thirumalesh yeligar
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to count number of vowels and consonents from a file........

my logic is: 1)creating the arraylist
2)open the file
3)and spliting the contents based on spaces
4)storing these strings in arraylist


now i'm really confused how to traverse the arraylist and how to check for vowels and cons.... please give me suggestion from here....


Thanks a LOT..............................
 
Niraj Jha
Ranch Hand
Posts: 63
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you use arraylist?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thirumalesh yeligar wrote:how to count number of vowels and consonents from a file........

Well, the first thing is to decide what a 'vowel' and a 'consonant' are - and there's no hard and fast rule for things like 'y' (and in some cases 'h').

However, like Niraj, I wonder about the wisdom of an ArrayList - but it's purely an 'efficiency' concern; you can certainly do it that way, and there's absolutely nothing wrong with the idea.

Winston
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) stop
2) don't think about how you'd do this in java. think about how you'd do this with pencil, paper, and your own brain.
3) write down in English (or your natural language of choice) how you would do it.
4) Revise those steps until you could give them to a child, and they could follow them
5) Give that list to a child to find out where you went wrong explaining the steps, and revise. Repeat this as many times as necessary.

ONLY when you have done all the above should you consider writing a single line of code. If you are already thinking about array lists and strings, you haven't though through the problem yet. You are jumping the gun.
 
Thirumalesh yeligar
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
without using arraylist how can i do it?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thirumalesh yeligar wrote:without using arraylist how can i do it?

Practically any Java collection or Map - or indeed an array (which may be fastest of all). But I just told you that you CAN do it with an ArrayList, so why are you looking around for other alternatives?

First, follow Fred's advice and get it working. Then, if you need to (and you still have time), worry about making it fast.

Winston
 
Jamie Coleshill
Greenhorn
Posts: 8
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try the following code with each line of data you get from the file.

[Moderator action: solution removed]

 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jamie Coleshill wrote:You could try the following code...

Jamie. Please DontBeACodeMill (←click).

I'm sure your motives were great, but we like to help people here, rather than just handing out solutions - especially in the 'Beginning Java' section.

By all means post something that helps Thirumalesh find his own solution, but try to avoid spoon-feeding.

Thanks.

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!