What is the largest number. I can not understand what's missing?

0

I'm doing some for loop exercises to apply what I've learned. In this classic exercise ask for 10 numbers for the user and show in the end which one is the greatest. I did so:

import java.util.Scanner;

public class TheBiggerNumber{
    public static void main (String[] args){

        Double[] numbers = new Double[10];
        Double theBigNumber = 1.0;
        Double lessNumber = 0.0;
        Double comparativeNumber = 0.5;
        Scanner in = new Scanner(System.in);

        for (int i=0; i<10; i++){
            System.out.println("Write 10 numbers randomly");
            numbers[i] = in.nextDouble();
            numbers[i] = comparativeNumber;
                if ( comparativeNumber > theBigNumber) {
                    theBigNumber = numbers[i];
                } else {
                        lessNumber = numbers[i];
                }
        }
        System.out.println("The Bigger number is: " + theBigNumber );
    } //end method main
} //end class

The program compiles and runs, but the result does not increment theBigNumber, the greater number is always what I declare for theBigNumber.

Can anyone help me?

    
asked by anonymous 10.04.2017 / 00:12

1 answer

0

The problem is on the line

numbers[i] = comparativeNumber;

You are assigning the value 0.5 to the number in the i-position of the vector and not giving the comparativeNumber the value of the i-th position. As 0.5 < 1, theBigNumber value never changes.

    
10.04.2017 / 00:19