Skip to content

Commit 8887641

Browse files
authored
feat: adds Dwight's sample code (#152)
1 parent 5328d4d commit 8887641

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

lesson_04/cdbluejr/Prime.bas

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
100 rem find prime number
2+
110 n =1
3+
120 c=0
4+
130 i=1
5+
140 if i<=n or (n mod i)<>0 then 300
6+
145 if i=n and c=2 then 200
7+
150 c=c+1
8+
160 if i>n then 210
9+
170 goto 130
10+
11+
200 Print n + “Prime"
12+
210 c=0
13+
220 n=n+1
14+
230 if c>n then 120
15+
240 goto 130
16+
17+
300 i=i+1
18+
310 goto 140

lesson_04/cdbluejr/Prime.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public class Prime {
2+
public static void main(String[] args) {
3+
4+
5+
int num = 29;
6+
int count = 0;
7+
for(int i=1; i<=num; i++) {
8+
if(num % i ==0) {
9+
count++;
10+
}
11+
}
12+
if(count==2) {
13+
System.out.println("Prime");
14+
} else {
15+
System.out.println("not Prime");
16+
}
17+
}
18+
}
19+

lesson_04/cdbluejr/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
## Java implementation
2+
3+
int num = 29;
4+
int count = 0;
5+
for(int i=1; i<=num; i++) {
6+
if(num % i ==0) {
7+
count++;
8+
}
9+
}
10+
if(count==2) {
11+
System.out.println("Prime");
12+
} else {
13+
System.out.println("not Prime");
14+
15+
16+
## Basic implementation
17+
18+
100 rem find prime number
19+
110 n =1
20+
120 c=0
21+
130 i=1
22+
140 if i<=n or (n mod i)<>0 then 300
23+
145 if i=n and c=2 then 200
24+
150 c=c+1
25+
160 if i>n then 210
26+
170 goto 130
27+
28+
200 Print n + “Prime"
29+
210 c=0
30+
220 n=n+1
31+
230 if c>n then 120
32+
240 goto 130
33+
34+
300 i=i+1
35+
310 goto 140
36+
37+
## Explanation
38+
39+
The java implementation uses the counting system to only count to 2, to signify a prime number.
40+
41+
The basic implementation also uses the counting system to only count to 2, to signify a prime number.
42+
43+
### Differences
44+
45+
1. **Syntax**:
46+
- In Java, it uses the fuctions Modelo function to determine if the reminder is zero to determine if the number is divisable evenly.
47+
- Basic uses the if then else function to determine if the number is prime or not.
48+
49+
3. **Function Calls**:
50+
- The ability to print for both programs are different, java uses System.out.println, while BASIC just uses the word print.
51+

0 commit comments

Comments
 (0)