Originally posted by Lorry`:
What is the output of the following loop structures:
a. for (int i=1; i < 5; i++) {
System.out.println( i + “ “);
}
b. for (int i = 5; i < 10; i = i+2) {
System.out.println( i + “ “);
}
c. for (int i = 1; i < 10; i = i*2) {
System.out.println(i + “ “);
}
________
Write the for-loop structure and a while loop structure to print numbers in the following manner .
6 7 8 9 10
___________
Write a program called MathApp containing the following methods:
a. A method with one argument radius and a return value of the area of circle. The method should calculate the area of the circle using the formula area = pi*radius*radius (where pi=3.14).
b. A method with two arguments radius and height, and a return value of the volume of a cone. The method should calculate the volume of a cone using the formula volume = (1/3.0)*pi*radius*radius*height (where pi=3.14).
c. The main method that calls the above methods that you have written with these values:
i. Circle1 with radius = 3 cm
ii. Cone1 with radius = 1 cm and height = 4 cm
iii. Circle2 with radius = 4.5 cm
iv. Cone2 with radius = 0.5 cm and height = 2 cm
thanks
part A
create a method called AreaCircle
It would look like this
public static double AreaCircle(double radii)
inside it would process something like this.
final double pi = 3.142;
double area = pi * radii * radii;
return area;
And finally u can sys.out.println(area); in your main method.
part B, this one call it say, VolumeCone. same as above, except u need to create another double value called height.
it would look something like this.
public static double VolumeCone(double radii, double height)
same thing
final double pi = 3.142;
double volume = pi * radii * radii * height * (1/3);
and then return volume.
part C, would be ur main method.
so in ur main method, u just call all the mthod n run lor.
i. Circle1 with radius = 3 cm ----> AreaCircle(3)
ii. Cone1 with radius = 1 cm and height = 4 cm ----> VolumeCone(1,4)
Iii. Circle2 with radius = 4.5 cm ----> AreaCircle(4.5)
iv. Cone2 with radius = 0.5 cm and height = 2 cm ----> VolumeCone(0.5,
Oh any u need to create a double variable for each of the circle and cone.
Eg double circle1 = AreaCircle(3);
correct me if im wrong.