Skip to content

Commit 0d1c797

Browse files
committed
Fix Formatting Errors
1 parent ede69c0 commit 0d1c797

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/com/codefortomorrow/advanced/chapter13/practice/PrimePractice.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@
1010
In your main method, include a scanner so the user can check
1111
as many numbers as they want until they enter -1.
1212
*/
13-
public class PrimePractice {}
13+
14+
public class PrimePractice {
15+
16+
}
Binary file not shown.

src/com/codefortomorrow/advanced/chapter13/solutions/PrimePractice.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.codefortomorrow.advanced.chapter13.practice;
22

3-
import java.lang.Math;
43
/*
54
Write a method called isPrime which returns
65
true if the given integer is prime and false otherwise.
@@ -14,6 +13,8 @@
1413
Note: There are more complex solutions, but this is the fastest one
1514
within the scope of this chapter.
1615
*/
16+
17+
import java.lang.Math;
1718
import java.util.Scanner;
1819

1920
public class PrimePractice {
@@ -25,21 +26,25 @@ public static void main(String[] args) {
2526
System.out.print("Enter an integer to check: ");
2627
s = reader.nextInt();
2728
if (s != -1) {
28-
if (isPrime(s, 2)) System.out.println(
29-
"That is a prime!"
30-
); else System.out.println("Not a prime!");
29+
if (isPrime(s, 2))
30+
System.out.println("That is a prime!");
31+
else
32+
System.out.println("Not a prime!");
3133
}
3234
}
3335
}
3436

3537
//n is the number to check, z is the current number being divided
3638
public static boolean isPrime(int n, int z) {
3739
//Check base cases
38-
if (n <= 2) return (n == 2) ? true : false;
40+
if (n <= 2)
41+
return (n == 2) ? true : false;
3942
//Ternary operator used there
40-
if (n % z == 0) return false;
43+
if (n % z == 0)
44+
return false;
4145
//If z gets high enough that z > sqrt(n), then n is prime, because factors just repeat after
42-
if (Math.pow(z, 2) > n) return true;
46+
if (Math.pow(z, 2) > n)
47+
return true;
4348

4449
//If none of the above work
4550
return isPrime(n, z + 1);

0 commit comments

Comments
 (0)