473,797 Members | 2,970 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Counting Vowels and Words with Eclipse

1 New Member
Hi! I'm using Eclipse as an IDE, I need to code a program where users enter a string and it computes the count for each vowel, and how many words are in the string. Users can do as many strings as they want until they hit cancel. This is what I have so far:

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2. public class Program 
  3. {    //Open Class
  4.     public static void main(String[] args)
  5. {    //Open Main
  6.         String input, output;    //Holds input and output.
  7.         int aCount = 0, eCount = 0, iCount = 0, oCount = 0, uCount = 0,  numLines = 0; //Holds values for entries of respective vowels. All initialized to 0.
  8.         char v = 0;    //v standing for vowel    
  9.  
  10.         String text = null;
  11.         do
  12. {
  13.         input    =    JOptionPane.showInputDialog("Input a line to analyze or Cancel to quit: ");
  14.         input    =    input.toLowerCase();
  15.         input.length();
  16.         numLines    =    numLines + 1;        
  17.         for (int wCount = 0; wCount < text.length(); wCount++)
  18.         v = text.charAt(wCount);
  19.         switch (v)
  20. {//Open switch statement. Braces are not used because there is only 1 corresponding statement per case.
  21.     case 'a':
  22.     aCount = aCount + 1;
  23.     break;
  24.     case 'e':
  25.     eCount = eCount + 1;
  26.     break;
  27.     case 'i':
  28.     iCount = iCount + 1;
  29.     break;
  30.     case 'o':
  31.     oCount = oCount + 1;
  32.     break;
  33.     case 'u':
  34.     uCount = uCount + 1;
  35.     break;
  36.  
  37. }//Close switch statement
  38.     JOptionPane.showMessageDialog(null, "A-Count: " + aCount + "\n" + "E-Count: " + eCount + "\n" 
  39.             + "O-Count" + oCount + "\n" + "U-Count" + uCount + "\n" + "Word Count" + v +  "Line Analisys - name here", text, JOptionPane.PLAIN_MESSAGE);
  40. }//Close do while    
  41.     while (input != null);
  42.  
  43.  
  44. }//Close Main
  45. }//Close Class
  46.  
I have no idea where i'm going wrong, or if i'm even headed in the right direction =\
Oct 5 '08 #1
2 4132
r035198x
13,262 MVP
So what happens when you (attempt to) compile/run your program?
Oct 6 '08 #2
chelvan
90 New Member
well

your char variable Declaration
Expand|Select|Wrap|Line Numbers
  1. char v='o';
  2.  
you are missing the single code ' ' on the assign value.

then next

your for loop, i thought the switch block should be under the for block. but on your code you missed to define the for block.

then allright.

regards
chel-1
Oct 7 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

31
2977
by: Brynn | last post by:
I want to thank the person that sent the nasty messages to my contact.asp test page ... you have inspired me !!! I have now added a bad_words filter both to my JSValidation script (going up on my site soon) and my contact.asp tool. I would have forgotten about it if it were not for you. I TRULY appreciate your help ... and hope that you helping me eats you up inside ... ROFL.
3
2150
by: mark | last post by:
hi guys i need hlp on a c programcounting letters,words,etc .simple. thanks
6
1881
by: gk245 | last post by:
Basically, i want to make a function that will receive a sentence or phrase, and count its words. It would start like this (i think): #include <stdio.h> int count ( char sentence ) { char string ;
1
2431
by: powerej | last post by:
I have gotten the part of counting how many words are in the string, but the vowels just seem alien to me. Ive tried so many things but never close to a correct answer. I know I need to use charAt() and length() some nested loops with do while and for, but cant seem to get headed in the right direction. Also when i click the cancel button my program is suppose to end and tell you how many lines were entered, a count of vowels from all lines...
0
1222
by: arnuld | last post by:
any comments for improvement: /* C++ Primer - 4/e * * CHAPTER 10 - Associative Containers * * EXERCISE - 10.7 * Write a program to count and print the number of times each word * occured in the input. *
0
864
by: Franzi | last post by:
Hello, how can I count words in Word alphabetically? So that it shows me how many words of each letter I have (shown in the alphabetical order). Thank you!
12
10046
by: ashpats | last post by:
Hey everyone, I am supposed to write a program that counts the number of vowels in string of characters. It must include "Struct counter_t (it must be declared as in the code i've written)" and function "int CountVowels (IN text, OUT Count)". the OUT parameter must be of type counter_t. I've written the code but it doesn't seem to work. Can someone help me please??? ...
6
4289
by: HypeBeast McStreetwear | last post by:
Hi I'm supposed to be writing a program that counts in a given text, the words that contain at least three different vowels (a,e,i,o,u) For my test run I have to use "unquestionably", but I can't anything to work. Here's what I have so far. #include <iostream> #include <string> #include <cstring> using namespace std;
3
3129
tpgames
by: tpgames | last post by:
I do not understand why this code does not work? It will show ????? for the word length, but will does not actually access the individual letters within the word list. I enter the vowels as guesses, and NONE of the vowels are said to be in the word. I'm trying to put the working code in a separate JS file, instead of having the silly thing on the same HTML page. This might allow me to incorporate user choosing which game to play within the same...
0
10245
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10205
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9063
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7559
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5458
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.