Computer Applications
John was asked to write a Java code to calculate the surface area of a cone. The following code was written by him: Surface area of cone is A = πrl l = class area{ double area(double r, double h){ double l, a; a = 22.0 / 7 * r * l; l = Math.sqrt(r * r + h * h); return a; } } Specify the type of the error in the above program, correct and write the program to be error free.
class area{
double area(double r, double h){
double l, a;
a = 22.0 / 7 * r * l;
l = Math.sqrt(r * r + h * h);
return a;
}
}
Specify the type of the error in the above program, correct and write the program to be error free.
Related Questions
Consider and give the output of the following program:
class report{ int a, b; report(){ a = 10; b = 15; } report(int x, int y){ a = x; b = y; } void print(){ System.out.println(a * b); } static void main(){ report r = new report(); r.print(); report p = new report(4, 5); p.print(); } }(a) Name one String method which results in positive integer only.
(b) Name one String method which results in a character.
Consider the following array and answer the questions given below:
int a[] = {12, 10, 8, 4, 6, 2, 3, 5, 7};
(a) What is the output of System.out.print(a[0] + a[5]);?
(b) What is the index (subscript) of the largest element of the array a[]?
(a) Write the Java statement to initialize the first 6 odd numbers in a 3 × 2 array.
(b) What is the result of x[0][1] + x[2][1] of the above array?