Skip to content

Commit 39c94a0

Browse files
authored
feat: adds Shawn lesson04 code samples (#144)
* inital commit * Final Commit Lesson 04 * Updated ReadMe
1 parent d7d4d1b commit 39c94a0

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

lesson_04/shawndunsmore/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## Java Method
2+
```java
3+
4+
if (number <= 1){
5+
return false;
6+
}
7+
8+
for (int i = 2; <= Math.sqrt(number); i ++){
9+
if (number % i == 0){
10+
return false;
11+
}
12+
}
13+
14+
return true;
15+
16+
```
17+
18+
## Python Method
19+
```Python
20+
def is_prime(number):
21+
if number <= 1:
22+
return False
23+
24+
for i in range(2, int(math.sqrt(number)) + 1):
25+
if number % i == 0:
26+
return False
27+
28+
return True
29+
```
30+
## Explanation
31+
We start off with both methods making sure the input number is less then or equal to one. Then it redirects down to see if the number comes back as false. Once checked with i to see if the number can be divided by one its checked through with are % operator. Once are loop is complete if it tracks no false numbers then it'll return true.
32+
33+
34+
## Differences
35+
* Both functions are called differently (`java: system.out.print` `Python print`)
36+
37+
* Both languages import math differently (`java: import java.lang.Math`; `Python: import math`)
38+
## Similarities
39+
* Both languages use `math.sqrt` equally to find the square root of the number. (well if you wanna be technical "java" has it start with a capital M but come on man.)
40+
41+
* In both methods Java and Python still use if statements to make choices in the code.
42+
"Used Ai to give me code prompts of python and java"

0 commit comments

Comments
 (0)