-3

I can't find my error here?

import java.util.Scanner;
    class Code {
            public static void main (String[] args) {
                    Scanner a = new Scanner (System.in);
                    System.out.println("Please, Enter Array Size : ");
                    int size = a.nextInt();
                    double[] arr = new double[size];
                    System.out.println("Enter Array elements : ");
                    for (int i = 0; i < size; i++) {
                            arr[i] = a.nextDouble();
                    }
                    int max = arr[0];
                    int min = arr[0];
                    for (int i = 1; i < size; i++) {
                            if (max < arr[i]) {
                                    max = arr[i];
                            }
                            if (min > arr[i]) {
                                    min = arr[i];
                            }
                    }
                    System.out.println("maximum is : " +max);
                    System.out.println("minimum is : " +min);
            }
    }

closed as off-topic by Kusalananda, roaima, Mr Shunz, Shadur, Jaroslav Kucera Jan 11 at 11:35

  • This question does not appear to be about Unix or Linux within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    This is a pure programming question and has nothing to do with Unix or Linux. Please post programming questions to Stack Overflow instead. – Haxiel Jan 11 at 7:22
0

Your are getting error because of different data types. The array you have defined is of double data type, but the min and max variables are of int type. So make them of double data type like:

double min,max;

If you want to keep min and max of int data type then you need to typecast the array element like:

min=(int)a[0];

but it is not recommended.

  • ohhooo!!! Thank you very much. I did it on 'C', but there no error. I shift few day's ago in java, & i have faced many small problem,which is getting bigger for me! In that case i was thinking 'C' is better then 'java' :) – Lidan Suidan Jan 11 at 6:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.