Java – Finding minimum and maximum values in an array [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












-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);











share|improve this question















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















-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);











share|improve this question















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













-3












-3








-3


0






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);











share|improve this question
















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);








java






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 12 at 1:14









Rui F Ribeiro

39.6k1479132




39.6k1479132










asked Jan 11 at 6:32









Lidan SuidanLidan Suidan

12




12




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.







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












  • 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







1




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





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










1 Answer
1






active

oldest

votes


















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.






share|improve this answer

























  • 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

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









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.






share|improve this answer

























  • 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















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.






share|improve this answer

























  • 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













0












0








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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 11 at 6:44

























answered Jan 11 at 6:38









P_YadavP_Yadav

1,85031024




1,85031024












  • 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

















  • 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
















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





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


Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay