From 516ece7b60c6e9837511a293290f31db38b579ac Mon Sep 17 00:00:00 2001 From: kellytang Date: Wed, 6 Jul 2022 14:53:07 +0800 Subject: [PATCH] new --- tutorial/CalMinNumOfCoins.java | 28 ++++++++++++++++++++++++++++ tutorial/CalSumOfGeo.java | 30 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 tutorial/CalMinNumOfCoins.java create mode 100644 tutorial/CalSumOfGeo.java diff --git a/tutorial/CalMinNumOfCoins.java b/tutorial/CalMinNumOfCoins.java new file mode 100644 index 0000000..e5bf035 --- /dev/null +++ b/tutorial/CalMinNumOfCoins.java @@ -0,0 +1,28 @@ +package tutorial; + +import java.util.Scanner; + +public class CalMinNumOfCoins { + public static void main(String[] args) { + + Scanner input = new Scanner(System.in); + + int amount; + int coinTen, coinFive, coinTwo, coinOne; + + System.out.print("Input an amount: "); + amount = input.nextInt(); + + coinTen = amount / 10; + coinFive = (amount % 10) / 5; + coinTwo = ((amount % 10)% 5) / 2; + coinOne = (((amount % 10)% 5)%2) / 1; + + System.out.println("The minimum numbers of coins for " + amount + " are:"); + System.out.println(coinTen + " 10-dollar coin(s)"); + System.out.println(coinFive + " 5-dollar coin(s)"); + System.out.println(coinTwo + " 2-dollar coin(s)"); + System.out.println(coinOne + " 1-dollar coin(s)"); + + } +} diff --git a/tutorial/CalSumOfGeo.java b/tutorial/CalSumOfGeo.java new file mode 100644 index 0000000..b7b63e9 --- /dev/null +++ b/tutorial/CalSumOfGeo.java @@ -0,0 +1,30 @@ +//Math.pow(R,n), R to the power of n +//a * R to the power of n and divided by R - 1 + +package tutorial; + +import java.util.Scanner; + +public class CalSumOfGeo { + public static void main(String[] args){ + double a, R, n; + Scanner input = new Scanner(System.in); + + double sumofGS; + + System.out.print("Enter the first number of the sequence: "); + a = input.nextDouble(); + + System.out.print("Enter the common ratio of the sequence: "); + R = input.nextDouble(); + + System.out.print("Enter the number of the terms of the sequence: "); + n = input.nextDouble(); + + sumofGS = (a*(Math.pow(R,n)-1))/(R-1); + + System.out.print("The sum of Geometric Series: "); + System.out.printf("%1.1f\n" , sumofGS); + + } +} \ No newline at end of file