Skip to content

Commit 4980f5e

Browse files
committed
chore:pushing changes up
1 parent 1dd4f62 commit 4980f5e

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Python examples
2+
3+
def is_prime(n):
4+
if n < 2:
5+
return False
6+
for i in range(2, int(n**0.5) + 1):
7+
if n % i == 0:
8+
return False
9+
return True
10+
11+
# Example usage
12+
num = 29
13+
if is_prime(num):
14+
print(f"{num} is a prime number.")
15+
else:
16+
print(f"{num} is not a prime number.")
17+
18+
19+
20+
Java Examples
21+
22+
public class PrimeChecker {
23+
public static boolean isPrime(int n) {
24+
if (n < 2) return false;
25+
for (int i = 2; i <= Math.sqrt(n); i++) {
26+
if (n % i == 0) return false;
27+
}
28+
return true;
29+
}
30+
31+
public static void main(String[] args) {
32+
int num = 29;
33+
System.out.println(num + " is prime: " + isPrime(num));
34+
}
35+
}
36+
37+
Similarties
38+
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
39+
vided or not crtical in figuring out if the number is prime.
40+
41+
Differences
42+
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)