Skip to content

Commit 3fcfc7e

Browse files
TatsuyaRyujinDavisD251anthonydmaysJeremiahwingTezz03
authored
feat: adds Evan's code samples (#151)
* chore: created main.cpp * chore: updated branch * chore: added header.hpp * feat: added isPrime func * test: added more test cases * chore: added Main.java * feat: finished Main.java * chore: added Main.class * chore: added README.md * chore: added c++ explanation * chore: finished README.md * feat: adds David's custom quiz (#139) Co-authored-by: DavisD. <[email protected]> Co-authored-by: Anthony D. Mays <[email protected]> * feat: adds Jeremiah's HTML README (#155) * finish css * Finished CSS For 001 HW * fix; added images and moved files to jeremiahwing folder * chore: updates Montez's custom quiz (#140) Co-authored-by: “Tezz03” <“[email protected]”> Co-authored-by: Anthony D. Mays <[email protected]> * fix: deleted c++ and java files --------- Co-authored-by: DavisD251 <[email protected]> Co-authored-by: DavisD. <[email protected]> Co-authored-by: Anthony D. Mays <[email protected]> Co-authored-by: Jeremiahwing <[email protected]> Co-authored-by: Tezz03 <[email protected]> Co-authored-by: “Tezz03” <“[email protected]”>
1 parent c5c30de commit 3fcfc7e

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

lesson_04/evanphilakhong/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Evan Philakhong
2+
3+
## C++ implementation
4+
5+
#### main.hpp
6+
```c++
7+
#include <iostream>
8+
#include <string>
9+
using namespace std;
10+
11+
// function definition
12+
bool isPrime(int num);
13+
```
14+
#### main.cpp
15+
```c++
16+
bool isPrime(int num) {
17+
int count = 0;
18+
for (int i = num; i > 0; i--) {
19+
if (num%i == 0) {
20+
count++;
21+
}
22+
}
23+
if (count == 2) {
24+
cout << "This is a Prime Number" << endl;
25+
return true;
26+
}
27+
cout << "This is not a Prime Number" << endl;
28+
return false;
29+
}
30+
```
31+
32+
## Java implementation
33+
34+
```java
35+
public static boolean isPrime(int num) {
36+
int count = 0;
37+
for (int i = num; i > 0; i--) {
38+
if (num%i == 0) {
39+
count++;
40+
}
41+
}
42+
if (count == 2) {
43+
System.out.println("This is a Prime Number");
44+
return true;
45+
}
46+
System.out.println("This is not a Prime Number");
47+
return false;
48+
}
49+
```
50+
51+
## Explanation
52+
53+
The **C++** implementation is using a function named `isPrime` that takes a single parameter `num` representing the number the function is checking if it's a prime number or not. The function returns `True` if the number is **Prime**, otherwise it returns `False`.
54+
55+
The **Java** implementation is using a function named `isPrime` that takes a single parameter `num` representing the numer the function is checking if it's a prime number or not. The function returns `True` if the number is **Prime**, otherwise it returns `False`.
56+
57+
### Differences
58+
59+
1. **File Stucture**:
60+
- In **C++**, you have the ability to create a header file to store libraries and function declorations. While Java has no such thing.
61+
- **Java** forces you to work in a `Class` while, **C++** lets you work outside of `Classes`
62+
63+
2. **Syntax**:
64+
- The syntax for printing to the console/output is a little different. **C++** uses `cout` while, **Java** uses `System.out.print();`

0 commit comments

Comments
 (0)