The objective of this program is to return the atomic mass from a given formula (as a String), using a CSV file that contains elements and their atomic masses. My code for this particular problem is this: I have another method “fileReader” that takes the data from the mile and returns a map with the elements as the key and
Tag: double
Filter distinct groups and get average of String values parsing as Integer or Double
I have a POJO like below: And a List like below: Now I am trying to filter and group all the employees by department and need to get the highest spending department. If salary is of type Double (say) I can do it like below: And I get the expected output: But I am clueless what to do if I
Comparison of Double Constants
I researched this a lot and I know something about precision errors in the doubles; however I couldnt find the answer. My question is: is it always safe to compare double constants? What do I mean by that is, just reading the double from a string or creating in the source code. No operation (adding, subtracting etc.) will be done
How can I intentionally create random floating point / decimal precision errors in java?
My goal is to generate random numbers that all have decimal precision errors. Here are some examples of types of numbers I would like to generate: 1.8181818723678589 1.2727272510528564 0….
‘OptionalDouble.getAsDouble()’ without ‘isPresent()’ check
I’ve seen a bunch of solutions for this question but no matter what I try, IDEA still reports an error. Consider the following block: double testDouble= customClass.stream() .mapToDouble(…
Game Of Life game: Check 2D array 8 closest surroundings; ArrayIndexOutOfBoundsException issue
I have encountered this problem and i couldn’t find the solution. There is a 2D array with only zeros and ones in it (the size of the array doesnt really matter, i worked with 10×10). Zero means dead …
How to implement Body Mass Index (BMI)in Java
My problem is how can I implement without the Scanner method and with Math.round and Math.pow? Here is my code: import java.util.Scanner; public class BMI{ public static void main(String …
Trying to sort a Double Collection
I am trying to sort a Collection. I cant seem to get my code to work with what I have found online. Collection: [104.131119, 104.188937, 93.174548, 100.533096, 97.902247, 98.608619, 93.380054, 106….
how do you round up a double user input value in java? [closed]
Im a student whos making a simple grading system and Im struggling on how to do this when I type in a specific number it go down to else bypassing my else-if statements the numbers are 98, 67, 98, 80 …
How come declaring something as a double data type would lead the ide to think it is a integer?
I am very confused on how a declared double data type would lead to the intellij ide to believe I was requiring a int to declare. Can someone give me some insight on this? Here is the code in a …