For your homework, write a program that computes the surface area of a cylinder. Your program should read in the height of the cylinder and radius of the base, and it should both compute and output the surface area of the cylinder (being as exact as possible). Comment your solution here.
top of page
bottom of page
class Main {
public static void main(String[] args) {
double h = 7.5;
double r = 8;
double sa = Math.PI * h * r * 2 + Math.PI * 2 * r * r;
System.out.println(sa); }
}
class Main { public static void main(String[] args) { double h = 7.5; double r = 8; double sa = Math.PI * h * r * 2 + Math.PI * 2 * r * r; System.out.println(sa); } }
class Main { public static void main(String[] args) { double h = 6.0; double r = 2.5; double c = Math.PI * 2 * r; double a = Math.PI * Math.pow(r, 2); double s = 2 * a + c*h; System.out.println("The surface area is: " + s); } }
class Main { public static void main(String[] args) {
double h = 1.5; double r = 6.0; double s = 2 * r * h * Math.PI + 2 * Math.PI * r * r; System.out.print(s); } }
class Main { public static void main(String[] args) { double r = 3.0; double h = 4.5; double sa = 2 * Math.PI * r * h + 2 * (Math.PI * r * r); System.out.println(sa); } }
package Intro_to_Java_Class_6;
import java.util.Scanner;
public class Intro_to_Java_Class3_6_20 {
public Intro_to_Java_Class3_6_20() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
System.out.print("Height: ");
String in_h = in.next();
double h = Double.parseDouble(in_h);
Scanner in2 = new Scanner(System.in);
System.out.print("Radius: ");
String in_r = in.next();
System.out.print("");
double r = Double.parseDouble(in_r);
double C = 2*Math.PI*r;
double body = C*h;
double caps = 2*Math.PI*r*r;
double final_sa = caps + body;
System.out.print(final_sa);
}
}
import java.util.Scanner; class Main { public static void main(String[] args) { System.out.println("enter the radius" ); Scanner sc = new Scanner(System.in); float r = sc.nextFloat(); System.out.println("enter the height" ); float h = sc.nextFloat(); double sa = 2 * r * r *Math.PI + 2 * r *Math.PI * h; System.out.println(" The Surface Area is " + sa ); } }
import java.util.Scanner; class Main { public static void main(String[] args) { System.out.println(" Please enter the radius of the cylinder. " ); Scanner sc = new Scanner(System.in); float radius = sc.nextFloat(); System.out.println(" Please enter the height of the cylinder. " ); float height = sc.nextFloat(); double area = 2 * radius * radius *Math.PI + 2 * radius *Math.PI * height; System.out.println(" The Surface Area is ..." ); System.out.println(area); } }
class Main { public static void main(String[] args) { double h = 3.5; double r = 4.0; double s = 2 * r * r * Math.PI + 2 * Math.PI * r * h; System.out.println(s); } }