Skip to content

Commit 2604d7d

Browse files
JJ27actions-user
authored andcommitted
Bot: Prettified Java code!
1 parent 0d1c797 commit 2604d7d

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,4 @@
1111
as many numbers as they want until they enter -1.
1212
*/
1313

14-
public class PrimePractice {
15-
16-
}
14+
public class PrimePractice {}

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,21 @@ public static void main(String[] args) {
2626
System.out.print("Enter an integer to check: ");
2727
s = reader.nextInt();
2828
if (s != -1) {
29-
if (isPrime(s, 2))
30-
System.out.println("That is a prime!");
31-
else
32-
System.out.println("Not a prime!");
29+
if (isPrime(s, 2)) System.out.println(
30+
"That is a prime!"
31+
); else System.out.println("Not a prime!");
3332
}
3433
}
3534
}
3635

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

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

0 commit comments

Comments
 (0)