Solución del problema
Incluya Scanner sc= new Scanner(System.in);
en su código para leer la entrada desde la consola. Y usar sc.nextInt()
para leer entradas.
Y eliminar ;
después de for-loop
lo cual está terminando el bucle. Y está tratando de incrementar legs
en for-loop
lugar de x
cambiarlo a for (int x = 0; x<legs; x++)
.
Aquí está el código modificado que funcionó para mí.
int counter = 0;
int gas = 0;
int legs = 1;
double miles = 0;
int mph= 0;
Scanner sc= new Scanner(System.in);
System.out.print("How many gallons of gas in you tank (Integer 1-20):");
gas = sc.nextInt();
gas+=gas;
System.out.print("How many legs on your trip?: ");
legs=sc.nextInt();
for (int x = 0; x<legs; x++)
{
System.out.printf("Enter leg %d distance(Miles): ",x);
miles=sc.nextDouble();
System.out.printf("Enter leg %d Speed(MPH): ",x);
mph=sc.nextInt();
}
No hay comentarios.:
Publicar un comentario