From 9ce275c16d9657622e0329c79ec3aecd2d4289c8 Mon Sep 17 00:00:00 2001 From: Indrranil Pawar <112892653+Indrranil@users.noreply.github.com> Date: Sun, 21 May 2023 11:08:54 +0530 Subject: [PATCH] Update FibonacciNumber.java (#4195) --- .../thealgorithms/maths/FibonacciNumber.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/thealgorithms/maths/FibonacciNumber.java b/src/main/java/com/thealgorithms/maths/FibonacciNumber.java index 17a8de61..c39f2a8b 100644 --- a/src/main/java/com/thealgorithms/maths/FibonacciNumber.java +++ b/src/main/java/com/thealgorithms/maths/FibonacciNumber.java @@ -17,8 +17,8 @@ public class FibonacciNumber { * Check if a number is perfect square number * * @param number the number to be checked - * @return true if {@code number} is perfect square, otherwise - * false + * @return true if {@code number} is a perfect square, otherwise + * false */ public static boolean isPerfectSquare(int number) { int sqrt = (int) Math.sqrt(number); @@ -26,18 +26,17 @@ public class FibonacciNumber { } /** - * Check if a number is fibonacci number This is true if and only if at + * Check if a number is a Fibonacci number. This is true if and only if at * least one of 5x^2+4 or 5x^2-4 is a perfect square * * @param number the number - * @return true if {@code number} is fibonacci number, otherwise - * false + * @return true if {@code number} is a Fibonacci number, otherwise + * false * @link https://en.wikipedia.org/wiki/Fibonacci_number#Identification */ public static boolean isFibonacciNumber(int number) { - return ( - isPerfectSquare(5 * number * number + 4) || - isPerfectSquare(5 * number * number - 4) - ); + int value1 = 5 * number * number + 4; + int value2 = 5 * number * number - 4; + return isPerfectSquare(value1) || isPerfectSquare(value2); } }