My question is how to store the generated list of this array
.
On line numeros[i] = ...
if I understand correctly, you already do this, it saves in array
what is typed in the entry that can be read as double
.
As a suggestion, you can use Scanner.html#hasNextDouble
before to check if the typed content can be interpreted as a double
value:
Scanner kb = new Scanner (System.in);
double [] numeros = new double [10];
for (int i = 0; i < numeros.length; i++) {
System.out.println("Digite o próximo número: ");
if(kb.hasNextDouble()) {
numeros[i] = kb.nextDouble();
}
}
To display the contents of array
, you can do this:
System.out.println(Arrays.toString(numeros));
Or so:
for (double numero: numeros) {
System.out.println(numero);
}
See DEMO