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?