Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How would I convert the numbers within my array list to negative numbers?

I’ve been trying to figure this out for like 20 minutes, and I still can’t figure it out.

I’m trying to get each individual positive number within listOfNumbers to be negative in order to create a bar graph. I can give more pieces of the code if needed, I’m just completely unsure of what to do.

public void plotLevels(ArrayList<Double> listOfNumbers) {
    int base = 350;
    int left = 50;
    int step = 25;
    UI.setColor(Color.black);

    for(int i = 0; i <listOfNumbers.size(); i++) {
        UI.fillRect(left, base, 20, (listOfNumbers.get(i)));
        left += step;
    }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you want the number to be negative within the UI.fillRect, you can replace it with the following:

UI.fillRect(left, base, 20, (listOfNumbers.get(i) * -1));

Because you multiply the number with -1, it will become negavtive.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading