kellytang 3 лет назад
Родитель
Сommit
516ece7b60
2 измененных файлов: 58 добавлений и 0 удалений
  1. +28
    -0
      tutorial/CalMinNumOfCoins.java
  2. +30
    -0
      tutorial/CalSumOfGeo.java

+ 28
- 0
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)");
}
}

+ 30
- 0
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);
}
}

Загрузка…
Отмена
Сохранить