From d58fa9547529a1f3a0da4b87e4b452fb040c204c Mon Sep 17 00:00:00 2001 From: kellytang Date: Wed, 6 Jul 2022 18:16:10 +0800 Subject: [PATCH] update --- tutorial/CalSumOfGeo.java | 7 +++---- tutorial/CalVolOfCylinder.java | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 tutorial/CalVolOfCylinder.java diff --git a/tutorial/CalSumOfGeo.java b/tutorial/CalSumOfGeo.java index b7b63e9..01a2e3e 100644 --- a/tutorial/CalSumOfGeo.java +++ b/tutorial/CalSumOfGeo.java @@ -8,10 +8,9 @@ import java.util.Scanner; public class CalSumOfGeo { public static void main(String[] args){ double a, R, n; + double sumOfGeo; Scanner input = new Scanner(System.in); - double sumofGS; - System.out.print("Enter the first number of the sequence: "); a = input.nextDouble(); @@ -21,10 +20,10 @@ public class CalSumOfGeo { System.out.print("Enter the number of the terms of the sequence: "); n = input.nextDouble(); - sumofGS = (a*(Math.pow(R,n)-1))/(R-1); + sumOfGeo = (a*(Math.pow(R,n)-1))/(R-1); System.out.print("The sum of Geometric Series: "); - System.out.printf("%1.1f\n" , sumofGS); + System.out.printf("%1.1f\n" , sumOfGeo); } } \ No newline at end of file diff --git a/tutorial/CalVolOfCylinder.java b/tutorial/CalVolOfCylinder.java new file mode 100644 index 0000000..2c96a87 --- /dev/null +++ b/tutorial/CalVolOfCylinder.java @@ -0,0 +1,27 @@ +package tutorial; + +import java.util.Scanner; + +public class CalVolOfCylinder { + + public static void main (String [] args) + { + String strRadius , strLength; + double radius , length, volume; + Scanner input = new Scanner(System.in); + + System.out.print("Enter the radius: "); + strRadius = input.nextLine(); + + System.out.print("Enter the length: "); + strLength = input.nextLine(); + + radius = Double.parseDouble(strRadius); + length = Double.parseDouble(strLength); + + volume = Math.pow(radius,2) * Math.PI * length; + System.out.println("The volume of the cylinder with radius= " + radius + " and length= " + length + " is " + volume + "."); + + } + +} \ No newline at end of file