File tree Expand file tree Collapse file tree 2 files changed +28
-11
lines changed Expand file tree Collapse file tree 2 files changed +28
-11
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ bool isPrime(int num) {
7
7
count++;
8
8
}
9
9
}
10
- if (count== 2 ) {
10
+ if (count == 2 ) {
11
11
cout << " This is a Prime Number" << endl;
12
12
return true ;
13
13
}
Original file line number Diff line number Diff line change 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
- */
10
1
public class Main {
11
2
12
3
/**
13
4
* @param args the command line arguments
14
5
*/
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
+ }
15
21
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 );
17
34
}
18
35
19
36
}
You can’t perform that action at this time.
0 commit comments