Skip to content

Commit 3ba8af4

Browse files
committed
feat: finished Main.java
1 parent 435936b commit 3ba8af4

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

lesson_04/evanphilakhong/c++/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ bool isPrime(int num) {
77
count++;
88
}
99
}
10-
if (count==2) {
10+
if (count == 2) {
1111
cout << "This is a Prime Number" << endl;
1212
return true;
1313
}
Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
1-
/*
2-
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3-
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
4-
*/
5-
6-
/**
7-
*
8-
* @author Evan Philakhong
9-
*/
101
public class Main {
112

123
/**
134
* @param args the command line arguments
145
*/
6+
7+
public static boolean isPrime(int num) {
8+
int count = 0;
9+
for (int i = num; i > 0; i--) {
10+
if (num%i == 0) {
11+
count++;
12+
}
13+
}
14+
if (count == 2) {
15+
System.out.println("This is a Prime Number");
16+
return true;
17+
}
18+
System.out.println("This is not a Prime Number");
19+
return false;
20+
}
1521
public static void main(String[] args) {
16-
// TODO code application logic here
22+
System.out.println("Testing Prime Nums");
23+
isPrime(2);
24+
isPrime(3);
25+
isPrime(5);
26+
isPrime(7);
27+
isPrime(11);
28+
System.out.println("Testing Non-Prime Nums");
29+
isPrime(1);
30+
isPrime(4);
31+
isPrime(6);
32+
isPrime(8);
33+
isPrime(9);
1734
}
1835

1936
}

0 commit comments

Comments
 (0)