File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ Update the sample application with the snippet and add a test for it. After prov
2828* [ Factorial] ( #factorial )
2929* [ Fibonacci] ( #fibonacci )
3030* [ Lottery] ( #lottery )
31+ * [ Prime] ( #prime )
3132
3233### Media
3334* [ Capture screen] ( #capture-screen )
@@ -251,6 +252,29 @@ Update the sample application with the snippet and add a test for it. After prov
251252
252253[ ⬆ back to top] ( #table-of-contents )
253254
255+ ### Prime
256+
257+ ``` java
258+ public static boolean isPrime(int number) {
259+ if (number < 3 ) {
260+ return true ;
261+ }
262+ // check if n is a multiple of 2
263+ if (number % 2 == 0 ) {
264+ return false ;
265+ }
266+ // if not, then just check the odds
267+ for (int i = 3 ; i * i <= number; i += 2 ) {
268+ if (number % i == 0 ) {
269+ return false ;
270+ }
271+ }
272+ return true ;
273+ }
274+ ```
275+
276+ [ ⬆ back to top] ( #table-of-contents )
277+
254278## Media
255279
256280### Capture screen
You can’t perform that action at this time.
0 commit comments