473,402 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Counting Vowels and Words with Eclipse

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 4111
r035198x
13,262 8TB
So what happens when you (attempt to) compile/run your program?
Oct 6 '08 #2
chelvan
90
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
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...
3
by: mark | last post by:
hi guys i need hlp on a c programcounting letters,words,etc .simple. thanks
6
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 ) {...
1
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...
0
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 *...
0
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
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...
6
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...
3
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,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...
0
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...

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.