0

So I need some help and maybe you guys can check my code and see why it isn't working and what I'm missing.

Here is the code:

import java.util.Scanner;
public class min;
    public static void main(string[] args) {
        Scanner input = new Scanner(System.in);
        double[] list = new double[4];
        double min = list[0];
        System.out.print("Enter " + list.length + " numbers: ");
        for (int i = 0; i < list.length; i++) {
            list[i] = input.nextDouble();
            if (list[i] < min) {
                min = list[i];
            }
        }
        System.out.println(min);
    }
}

So, why does it bring back 0.0 when I have the greater than facing min?

When I flip the sign around it works and brings back the greatest number, when I put out a list of numbers it works both min and max, just not for minimum input.

Jason
  • 11,744
  • 3
  • 42
  • 46
Dumbfounded
  • 11
  • 1
  • 2
  • 6
  • 1
    That's not valid Java code. Please [edit] your question and improve it. Fix the indention, too. –  Feb 23 '16 at 21:27
  • And one thing independent of that. You should never compare doubles with <>= if you expect nearby values. Use some epsilon-based comparison in that case. Here is a starting point http://stackoverflow.com/questions/8081827/how-to-compare-two-double-values-in-java – Rainer Feb 23 '16 at 21:33
  • Jason I dont know how to fix the code, doesnt give me privelage as far as i know of. please forgive. – Dumbfounded Feb 23 '16 at 21:37

1 Answers1

0

You could also just initialize min as input.nextDouble after the user input, and change your for loop to start at 1