Skip to content

Commit ca7e75c

Browse files
feat: adds Justin's code samples (#165)
* re added work after syncing with main branch * chore: updates formatting and moves files Signed-off-by: Anthony D. Mays <[email protected]> * chore: updates formatting and moves files Signed-off-by: Anthony D. Mays <[email protected]> * chore: formatting Signed-off-by: Anthony D. Mays <[email protected]> --------- Signed-off-by: Anthony D. Mays <[email protected]> Co-authored-by: Anthony D. Mays <[email protected]>
1 parent d7b5c6b commit ca7e75c

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

lesson_04/justineklund/README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Python examples
2+
3+
```python
4+
def is_prime(n):
5+
if n < 2:
6+
return False
7+
for i in range(2, int(n**0.5) + 1):
8+
if n % i == 0:
9+
return False
10+
return True
11+
12+
# Example usage
13+
num = 29
14+
if is_prime(num):
15+
print(f"{num} is a prime number.")
16+
else:
17+
print(f"{num} is not a prime number.")
18+
```
19+
20+
21+
Java Examples
22+
23+
```java
24+
public class PrimeChecker {
25+
public static boolean isPrime(int n) {
26+
if (n < 2) return false;
27+
for (int i = 2; i <= Math.sqrt(n); i++) {
28+
if (n % i == 0) return false;
29+
}
30+
return true;
31+
}
32+
33+
public static void main(String[] args) {
34+
int num = 29;
35+
System.out.println(num + " is prime: " + isPrime(num));
36+
}
37+
}
38+
```
39+
40+
Similarties
41+
They both use if and for standards to go about the command. This essentially gives the computer a path to go through to make sure the number is prime or not. They also both use the true and false function. This tells the computer how to go about the next commands. Also they both use division. Division is important because if it can be di
42+
vided or not crtical in figuring out if the number is prime.
43+
44+
Differences
45+
A big difference is in the certain command language used. Examples begin in how they start. Java begins with public static and python begins with def is prime. This continues all throughout the code line with multiple commands being different.

0 commit comments

Comments
 (0)