Page 258 - CA_Blue( J )_Class10
P. 258
ob.check("Republic Day");
}
}
14. Design a class to overload a function sumSeries() as follows: [2016]
(i) void sumSeries(int n, double x): with one integer argument and one double argument to find and display the sum of the series
given below:
s = x / 1 - x / 2 + x / 3 - x / 4 + x / 5 … N terms.
(ii) void sumSeries(): to find and display the sum of the following series:
s = 1 + (1 × 2) + (1 × 2 × 3) + … + (1 × 2 × 3 × 4 … × 20)
Ans. class Overload_function{
void sumSeries(int n, double x){
double sum = 0.0,i;
for (i = 1; i <= n; i++) {
if(i%2==0)
sum -= x / i;
else
sum += x / i;
}
System.out.println("Sum = " + sum);
}
void sumSeries(){
long sum = 0L;
int i,f=1;
for (i = 1; i <= 20; i++)
{f *= i;
sum += f;
}
System.out.println("Sum = " + sum);
}
}
15. Design a class to overload a function joyString() as follows: [2015]
(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:
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.
Example:
INPUT:
s = "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.
Example:
INPUT:
s1 = "COMMON WEALTH"
256256 Touchpad Computer Applications-X

