File tree Expand file tree Collapse file tree 3 files changed +88
-0
lines changed Expand file tree Collapse file tree 3 files changed +88
-0
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments