0
I’m doing some loop-for exercises to apply what I’ve learned. In this classic exercise request 10 numbers for the user and show at the end which is the largest. 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 increase theBigNumber, the largest number is always what I declared for theBigNumber.
Can someone help me?
The objective of the exercise is to show the larger of 10 numbers typed only? Da para fazer sem utilizar 2/3 do esse codigo ai.
– user28595