Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.
import java.util.*;
class Mmin{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter 10 numbers: ");
double [] num = new double [10];
int j;
double finmin = 0;
for(j=0; j < num.length; j++){
num[j] = input.nextDouble();
finmin = min(num);
}
System.out.print("your lowest number is: " + (int)finmin);
}
public static double min(double[] num)
{
int j;
double finmin = 0;
for (j = 0; j < num.length; j++){
if (num[j] < j){
finmin = num[j];
}
else{
finmin = num[j];
}
}
return (finmin);
}
}
public static double min(double[] num)
{
int j;
double finmin = num[0];
for (j = 0; j < num.length; j++){
if (num[j] < finmin)
finmin = num[j];
}
return (finmin);
}
and call min() outside the for loop
import java.util.*;
class Mmin{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter 10 numbers: ");
double [] num = new double [10];
int j;
for(j=0; j < num.length; j++){
num[j] = input.nextDouble();
}
Arrays.sort(num);
System.out.println((int)num[0]);
}
}
I need help in figuring out why, as it was stated, I am stuck in a loop.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
double finmin = 0;
to
int finmin = 0;