-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForIntroduction.java
41 lines (31 loc) · 1015 Bytes
/
ForIntroduction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package Chapter2.src;
public class ForIntroduction {
public static void main(String[] args) {
int numberOfPrimes = 0;
for (int i = 50; i < 100; i++) {
if (isPrime(i)) {
System.out.println(i);
numberOfPrimes++;
} else if(numberOfPrimes == 3) {
break;
}
}
// for(int i = 8; i > 0; i--) {
// System.out.println("Cost with interest rate of " + i + " % = " +
// String.format("%.2f",calculateInterest(10000, (double) i)));
}
public static double calculateInterest(double amount, double interestRate) {
return (amount * (interestRate / 100));
}
public static boolean isPrime(int n) {
if (n == 1) {
return false;
}
for (int i = 2; i <= n / 2; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
}