Ver Mensaje Individual
  #3 (permalink)  
Antiguo 27/05/2010, 11:22
diduch
 
Fecha de Ingreso: febrero-2010
Mensajes: 29
Antigüedad: 15 años
Puntos: 1
De acuerdo Respuesta: Problema con operacion matematica

TU ERROR ES QUE NUNCA INGRESA AL WHILE XQ SIEMPRE TIENE COMO VALOR DE LA VARIABLE NUMERO EL CERO
EN LA PARTE QUE VAS A PRESENTAR LA RESPUESTA PRIMERO COMPARA SI EL CONTADOR ES CERO, PORQUE EN ESE CASO QUIERE DECIR QUE EL PRIMER VALOR INGRESADO ES UN NEGATIVO, ENTONCES TE ESTA TERMINANDO, EN ESE CASO MEJOR PRESENTA UN MENSAJE DE QUE NO EXISTE NUMEROS VALIDOS PARA SACAR EL PROMEDIO.

int numero = 1;
int suma = 0;
int contador = 0;
BufferedReader teclado = new BufferedReader(new InputStreamReader(System.in));

while (numero > 0) {
System.out.println("Introdusca numero ");
numero = Integer.parseInt(teclado.readLine());
if (numero >= 70 && numero <= 100) {
suma = suma + numero;
contador++;
}
}
if(contador==0){
System.out.println("NO SE INGRESO NINGUN NUMERO VALIDO PARA REALIZAR EL PROMEDIO");
}else{
System.out.println("el promedio es " + suma / contador);
}

si tienes algun problema me avisas, espero que te sirva de algo

Última edición por diduch; 27/05/2010 a las 11:30