Count Number of Vowels in Java GUI
Submitted by donbermoy on Wednesday, May 7, 2014 - 20:01.
In this tutorial, i will teach you how to create a program that counts how many vowels are inputted in a text using java that has a GUI interface.
Now, let's start this tutorial!
1. Open JCreator or NetBeans and make a java program with a file name of Vowels.java.
2. Import javax.swing package. Hence we will use a GUI (Graphical User Interface) here like the inputting the word.
3. Before coding in the Main, create first a function named countVowels as integer and a text variable as string as parameters for this function.
4. Initialized your variable in your Main, variable Str as string and make it as an input and an numVowels as Integer as a variable for finding and displaying the number of vowels.
5. Count the number of strings using the countVowels function that will hold the Str variable as an input and will be held by the numVowels variable.
6. Lastly, display the output of the program using JOptionPane.showMessageDialog to count how many vowels did the input string has.
Output:
Here's the full code of this tutorial:
Hope this helps! :)
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware
- import javax.swing.*;
- int count = 0; // start the count at zero
- // change the string to lowercase
- text = text.toLowerCase();
- //gets the vowel characters
- for (int i = 0; i < text.length(); i++) {
- char c = text.charAt(i);
- if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u') {
- count++;
- }
- }
- return count; //returns the number of vowels inputted
- }
- String Str;
- int numVowels;
- numVowels = countVowels(Str);
- import javax.swing.*;
- public class Vowels {
- String Str;
- int numVowels;
- numVowels = countVowels(Str);
- }
- int count = 0;
- text = text.toLowerCase();
- for (int i = 0; i < text.length(); i++) {
- char c = text.charAt(i);
- if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u') {
- count++;
- }
- }
- return count;
- }
- }
Add new comment
- 793 views