Page 255 - computer science (868) class 11
P. 255
4. Design a class vowel that accepts a string and prints the number of vowels present in each word of the string.
Also, note that a string is considered valid if it does not contain any repeated spaces. For example, String: India is a country.
Output: India: 3
is: 1
a: 1
country: 2
Use the following specifications:
Class name : vowel
Data Members
sen : the string
Member Methods
vowel() : to initialise the member string to null
void input() : to input the member string
void find() : to print “invalid Sting” if the string is not valid, otherwise print the words of the member string along
with the number of vowels present in them.
5. Design a class piglatin that accepts a string and prints its piglatin format.
In Piglatin, a word such as KING becomes INGKAY, TROUBLE becomes OUBLETRAY and so on. The first vowel of the original word
becomes the starting of the translation and the proceeding letter is shifted towards the end and followed by AY. The word that
begins with a vowel is left unchanged.
Use the following specifications:
Class name : piglatin
Data Members
sen : the string
nsen : string with piglatin format
Member Methods
piglatin() : to initialise the member string to null
void input() : to input the member string
void convert_piglatin() : to convert "sen" to its piglatin format and strore in "nsen"
void show() : to print both words.
6. Write a Java program to accept a binary number in a string and convert it into a decimal number. Also, convert each binary digit
into its complement and then convert it into a decimal number.
7. A name is to be said an odd name if the ASCII code of each character becomes an odd number. Write a program in Java to accept
a name and check whether the given name is an odd name or not.
8. Write a program in Java to display the given patterns.
a. a
a a A
a a a A a
a a A
a
b. a
a a A
a a a A a
c. a a a A a
b b b B b
c c c C c
d d d D d
e e e E e
d. a a
b b
c
d d
e e
253
Strings 253

