0

I'm working on a programme that's supposed to accept input of doubles from an array
however it's not quite working out for me.

It takes in Integers alright but not the double values.

Could someone point me in the right direction

Any help is much appreciated

double array[] = new double[10];
           int total = 0;
        for (int counter = 0; counter < array.length; counter++)
        {
          array[counter] = Integer.parseInt(JOptionPane.showInputDialog("Enter the figures for the array"));

          total= (int) (total+array[counter]);
        }
        int average = total/10;

        JOptionPane.showMessageDialog(null, "the total is "+total);
        JOptionPane.showMessageDialog(null, "the average is "+average);

    }
4
Contributors
3
Replies
17
Views
2 Years
Discussion Span
Last Post by samson.dadson.3_1
1

Integer.parseInt(... takes the string that the user entered and converts it to an int. You can put that into an array of doubles, but you will have lost everything after the decimal point. If you want to parse a string for a double value it's a very similar method... Double.parseDouble(...

Edited by JamesCherrill

0

to prevent future errors, total should be of type double, average should be of type double too.. and divide by 10.0 instead of 10.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.