Page 311 - CA_Blue( J )_Class10
P. 311
28 }
29 public static void main()
30 {
31 series ob = new series();
32 ob.input();
33 ob.display();
34 }
35 }
You will get the following output:
To create a class with the following specifications:
Program 3 Class name : vowel
Data Members
String str : Sentence to check
int vc : Number of vowels
Member Methods
vowel(String) : Parameterised constructor to initialize str
void count_vowels() : Counts the number of vowels in str
void display() : Prints str and the number of vowels
1 import java.util.*;
2 class vowel
3 { String str;
4 int vc;
5 vowel(String s)
6 { str=s;
7 vc=0;
8 }
9
10 void count_vowels()
11 { int i,l; char ch;
12 l=str.length();
13 str=str.toUpperCase();
14 for(i=0;i<l;i++)
15 { ch=str.charAt(i);
309
Constructors 309

