JAVA PROGRAMMING IN BLUEJ.
Design a class to overload a function compute( ) as follows :
(i) void compute( int,char ) : to compute the square of the integer argument if the given character argument is 's' otherwise find its cube.
(ii) void compute( double char ) : to compute volume of a cube if the given character argument is 'v' otherwise find its diagonal.
(iii) void compute( int, int, char ) : to compute area of a rectangle if the given character argument is 'a' otherwise find its perimeter.
Answers
Answered by
3
Ans.
public class Series {
public void SumSeries(int n, double x) {
double sum = 0;
for (int i = 1; i <= n; i++) {
if (i % 2 == 1) {
sum = sum + (x / i);
} else {
sum = sum - (x / i);
}
}
System.out.println("Sum = " + sum);
}
public void SumSeries() {
int sum = 0;
for (int i = 1; i <= 20; i++) {
int product = 1;
for (int j = 1; j <= i; j++) {
product = product * j;
}
sum = sum + product;
}
System.out.println("Sum = " + sum);
}
}
regarding ([email protected])
Similar questions