Page 283 - Cs_withBlue_J_C11_Flipbook
P. 283
Sample output:
w * d
r t *
k j *
27. Write a program in Java to print the following patterns.
a. ABCDE b. ABCDE c. A d. A
ABCD BCDE AB BC
ABC CDE ABC DEF
AB DE ABCD GHIJ
A E ABCDE
AB ABCD
ABC ABC
ABCD AB
ABCDE A
28. Design a class to overload a function Joystring() as follows:
(i) void Joystring (String s, char ch1, char ch2) with one string argument and two character arguments that replaces the character
argument ch1 with the character argument ch2 in the given string s and print the new string.
For example:
Input value of s =“TECHNALAGY”
ch1=‘A’,
ch2=‘O’
Output: “TECHNOLOGY”
(ii) void Joystring (String s) with one string argument that prints the position of the first space and the last space of the given
string s.
For example:
Input value of =“Cloud computing means Internet-based computing”
Output: First index: 5
Last index: 36
(iii) void Joystring ( String s1, String s2 ) with two string arguments that combines the two strings with a space between them and
prints the resultant string.
For example:
Input value of s1 =“COMMON WEALTH “
Input value of s2=“GAMES “
Output: COMMON WEALTH GAMES
(use library methods)
29. Write a program in Java to enter the names of 10 cities and their STD codes in two different 1 D arrays. The program displays the
output as per the user’s choice:
(i) If the user enters the STD code, then it displays the corresponding city
(ii) If the user enters the name of the city, then it displays its STD code
For example:
Choice : 1
Enter STD code : 011
New Delhi
Choice : 2
Enter city name : Lucknow
0522
Also, print the array with the cities whose names start with “A”.
30. Write a program in Java that reads a string and a character. Each occurrence of the given character (regardless of its case) is
converted to its opposite case.
Sample Input: AabrAcadabrA and ‘a’
Sample Output: aAbracAdAbra
(each ‘a’ or ‘A’ is converted to the opposite case, i.e., upper case to lowercase or vice-versa)
281
Strings 281

