My teacher wants us to display our values in the format method (at the very bottom) but the problem is we had a sub and she didn't show us how to use it and my teacher is being less than helpful. Any advice or help would be greatly appreciated.
public class SphereCalculations
{
public static void main(String[] args)
{
//define variables
double circumference = 0;
double area = 0;
double volume = 0;
double surfacearea = 0;
double radius = 0;
Scanner scan = new Scanner (System.in);
DecimalFormat dFmt = new DecimalFormat("0.0000");
//prompt for radius
System.out.println("Enter the sphere's radius: ");
radius = scan.nextDouble();
//calculate values
circumference = 2 * Math.PI * radius;
area = Math.PI * (Math.pow(radius, 2));
volume = ((4 / 3) * Math.PI) * Math.pow(radius, 3);
surfacearea = (4 * Math.PI) * Math.pow(radius, 2);
//Display values with println and DecimalFormat
System.out.println("Using Println");
System.out.println("The radius: " + radius);
System.out.println("Circumference: " + dFmt.format(circumference));
System.out.println("Area: " + dFmt.format(area));
System.out.println("Volume: " + dFmt.format(volume));
System.out.println("Surface Area: " + dFmt.format(surfacearea));
//Display values with format method
System.out.printf();
Here a few examples:
(The output is shown within double quotes in the embedded comment)
Note : System.out.format() = System.out.printf()
(source)