Java – Finding minimum and maximum values in an array [closed]
Clash Royale CLAN TAG#URR8PPP
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
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.
add a comment |
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
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.
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
add a comment |
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
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
java
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.
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.
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
add a comment |
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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