-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVovels.java
More file actions
48 lines (43 loc) · 1022 Bytes
/
Copy pathVovels.java
File metadata and controls
48 lines (43 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import javax.swing.*;
import java.awt.event.*;
public class Vovels implements ActionListener{
JLabel l1,l2;
JTextArea area;
JButton b;
Vovels (){
JFrame f = new JFrame();
l1 = new JLabel();
l1.setBounds(50,25,100,30);
l2=new JLabel();
l2.setBounds(160,25,100,30);
area = new JTextArea();
area.setBounds(20,75,250,200);
b= new JButton("Count word");
b.setBounds(100,300,120,30);
b.addActionListener(this);
f.add(l1);f.add(l2);f.add(area);f.add(b);
f.setSize(450,450);
f.setLayout(null);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String Str;
int numVowels;
Str=JOptionPane.showInputDialog(null,"Enter string");
numVowels=countVowels(Str);
}
static int countVowels(String text) {
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;
}
public static void main (String args[]) {
new Vovels();
}
}