Skip to content
Advertisement

calculate the percentage increase or decrease in a list of values in java

i’m trying to build an data structures and algorithms program using java. and i wanna ask if anyone know How do i calculate the percentage increase or decrease in a array. i try this code–but apparently its not the correct way

JavaScript
JavaScript

Run-> Percentage change is = Infinity %

Advertisement

Answer

Here you’re dealing with the numbers, which could go in the larger values. Datatype float has limited range to handle the numbers between 3.40282347 x 10e38 and 1.40239846 x 10e-45. So change the method return type of checkMov to double. Also handle the values in double, which ranges between 1.7976931348623157 x 10e308 and 4.9406564584124654 x 10e-324.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement