These vectors are in the main is a java desktop project.
Vectors:
double[] dato = new double[0];
double[] datoTemporal = new double[0];
String texto = "";
Insert:
if (dato.length == 0) {
dato = new double[1];
dato[0] = Double.parseDouble(JOptionPane.showInputDialog("Ingrese el valor: "));
} else if (dato.length > 0) {
datoTemporal = new double[dato.length + 1];
for (int i = 0; i < dato.length; i++) {
datoTemporal[i] = dato[i];
}
Here is where I have the question because it subtracts -1 from Temporal data and continues with the same size and printed its size before arriving here and after subtracting the -1 and the size does not change but if I remove it I get an error Someone explains to me because I get an error or that he does that -1.
datoTemporal[datoTemporal.length - 1] = Double.parseDouble(JOptionPane.showInputDialog("Ingrese el valor: "));
dato = new double[datoTemporal.length];
for (int i = 0; i < datoTemporal.length; i++) {
dato[i] = datoTemporal[i];
}
}
Show:
String texto = "";
if (dato.length >= 1) {
texto = "Numero de registros " + dato.length + "\n\n";
for (int i = 0; i < dato.length; i++) {
texto += "Posicion " + i + ": " + dato[i] + "\n";
}
JOptionPane.showMessageDialog(null, " " + texto, " Mostrar texto", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, " " + texto, " Error texto", JOptionPane.ERROR_MESSAGE);
}