-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMain.java
More file actions
56 lines (47 loc) · 1.34 KB
/
Main.java
File metadata and controls
56 lines (47 loc) · 1.34 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package For;
/**
* Created by robertsg on 11/20/2015.
*/
public class Main {
public static void main(String[] args) {
// go();
go2();
}
public static void go() {
//Challenge
for(int i = 2; i < 9; i++){
System.out.println("$10,000 at " + i + "% interest = $" + calculateInterest(10000.0,i));
}
System.out.println();
//Challenge 2
for(int i = 8; i > 1; i--){
System.out.println("$10,000 at " + i + "% interest = $" + calculateInterest(10000.0,i));
}
}
public static void go2() {
int count = 0;
for(int i = 1; i < 1000 ;i++){
if (isPrime(i)) {
System.out.println(i + " is a prime number");
count++;
}
if(count == 3) {
break;
}
}
}
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;
}
public static double calculateInterest(double amount, double interestRate) {
return (amount * interestRate / 100.0);
}
}