Skip to content

Commit 6b5d471

Browse files
authored
feature/lesson4 hw (#205)
1 parent 9503490 commit 6b5d471

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

lesson_04/hummadtanweer/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
3+
```Java
4+
static boolean checkPrime(int num) {
5+
boolean prime = false;
6+
if (num == 0 || num == 1) {
7+
prime = true;
8+
}
9+
for (int i = 2; i <= num / 2; i++) {
10+
if (num % i == 0) {
11+
prime = true;
12+
break;
13+
}git
14+
}
15+
return !prime;
16+
}
17+
18+
# Example usage:
19+
print(checkPrime(4)) # Output: false
20+
print(checkPrime(7)) # Output: true
21+
22+
## JavaScript implementation
23+
24+
```javascript
25+
function checkPrime(num) {
26+
let prime = false;
27+
if (num === 0 || num === 1) {
28+
prime = true;
29+
}
30+
for (let i = 2; i <= num / 2; i++) {
31+
if (num % i === 0) {
32+
prime = true;
33+
break;
34+
}
35+
}
36+
return !prime;
37+
}
38+
// Example usage:
39+
console.log(checkPrime(4)); // Output: false
40+
console.log(checkPrime(7)); // Output: true
41+
42+
43+
## Explanation
44+
45+
The Javascript implementation uses a function named `checkPrime` that takes a single argument `number`. It returns `True` if the number is prime, otherwise, it returns `False`.
46+
47+
The Java implementation uses a function named `checkPrime` that also takes a single argument `int number`. It returns `true` if the number is Prime and `false` otherwise.
48+
49+
Java uses `true` and `talse` for boolean values and JavaScript uses `true` and `false`.
50+
51+
### Differences
52+
53+
**Function Calls**:
54+
- The syntax for calling functions and printing to the console/output is slightly different. Java uses `print()`, while JavaScript uses `console.log()`.
55+
56+
**Citation
57+
https://www.programiz.com/java-programming/online-compiler/?ref=8039b165git

0 commit comments

Comments
 (0)