1. State the output of the following program segment: [2]

String str1=”great”;

String str2=”minds”;                                                                                                     System.out.println(str1.substring(0,2).concat(str2.substring(1)));

System.out.println(“WH”+(str1.substring(2).toUpperCase())));

  1. State the values stored in the variables str1 and str2  [2]

String s1=”good”;

String s2=”world matters”;

String str1=s2.substring(5).replace(‘t’,’n’);

String str2=s1.concat(str1);

  1. What is the data type that the following functions return ? [2]

i) isWhitespace(char ch);

ii) random();

  1. State the output of the following program segment. [2]

String s= “Examination”;

int n= s.length();

System.out.println(s.startsWith(s.substring(5,n)));

System.out.println(s.charAt(2)== s.charAt(6));

  1. State the method that: [2]

i) Converts a string to a primitive float data type

ii) Determines if the specified character is an uppercase character.

Program 1:

Design a class to overload a function Joystring( ) as follows: [ 15 ]

  1. 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 prints the new string.

Example:-

Input value of s = “TECHNALAGY”

ch1=’A’      ch2=’O’

Output:         “TECHNOLOGY”

 

  1. ii) void Joystring(String s) with one string argument that prints the position of the first space and last space of the given string s.

Example:-

Input value of s = “Cloud computing means Internet based computing”

Output:       First index : 5

Second index:36

 

iii) void Joystring(String s1, String s2) with two String arguments that combines the 2 strings with a space between them and prints the resultant string.

Example:

Input value ofs1= “COMMON WEALTH”

Input value ofs2= “GAMES”

Output:       COMMON WEALTH GAMES (use library functions)

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here