For my first code post I thought it might be appropriate to put the first code from the first lab of my first computer science class at Wheaton.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | import java.util.Scanner; public class Circle { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); // input from keyboard System.out.print("Please enter the radius-->"); double radius = keyboard.nextDouble(); // radius to work with double diameter = radius*2; System.out.println("The diameter is " + diameter); double circumference = Math.PI*2*radius; System.out.println("The circumference is " + circumference); double area = Math.PI * Math.pow(radius, 2); System.out.println("The area is " + area); double volume = (4.0 / 3.0) * Math.PI * Math.pow(radius, 3); System.out.println("The volume of a sphere is " + volume); double surfaceArea = Math.PI * 4 * Math.pow(radius, 2); System.out.println("The surface area of a sphere is " + surfaceArea); } } |