The problem I have is that I need to save the temperatures of a week in a file and when I do, the file only shows me the last temperature entered.
I do not know where the error is so that it shows me all the temperatures.
public class Principal {
public static void introducirTempe() throws IOException {
Scanner sc = new Scanner(System.in);
double dias[];
//int aux = 0;
String diasSemana[] = {"Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado", "Domingo"};
dias = new double[7];
for (int x = 0; x < diasSemana.length; x++) {
System.out.println("Introduce la temperatura del " + diasSemana[x]);
dias[0] = sc.nextDouble();
FileWriter f = null;
PrintWriter p = null;
try {
f = new FileWriter("Temperaturas.txt");
p = new PrintWriter(f);
for (int j = 0; j < dias.length; j++) {
p.println(dias[j]);
}
}catch (IOException e) {
System.out.println(e.getMessage());
}finally {
f.close();
}
}
}
I also leave the main
public static void main(String args[]) throws IOException {
Scanner sc = new Scanner(System.in);
int opcion = -1;
while (opcion != 0) {
System.out.println("MENU");
System.out.println("Selecciona una de las opciones ");
System.out.println("1. Introducir temperatura del dia");
System.out.println("2. Realizar estadistica");
System.out.println("3. Salir");
opcion = sc.nextInt();
switch (opcion) {
case 1:
introducirTempe();
break;
case 2:
//estadistica();
break;
case 3:
//salir();
break;
}
}
}
}