Txerrinko

Edades

Mar 18th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. package Ejercicio1;
  2.  
  3. import java.io.IOException;
  4.  
  5.  
  6.  
  7. public class ej1 {
  8.    
  9.     static float edadmedia(int[] edades){
  10.         int mediaed = 0;
  11.        
  12.         for (int i=0 ; i<edades.length;i++){
  13.             mediaed=mediaed+ edades[i];
  14.    
  15.         }
  16.      return mediaed / edades.length;   
  17.        
  18.     }
  19.    
  20.     public static void main(String[] args) throws IOException {
  21.         // TODO Auto-generated method stub
  22.     int[]edades=new int[10];
  23.    
  24.    
  25.    
  26.     int edadmax=-100;
  27.     int edadmin=240;
  28.    
  29.    
  30.        for (int i=0; i<edades.length;i++){
  31.            
  32.            System.out.println("Introduce edad");
  33.             edades[i]=Consola.leeInt();
  34.            
  35.             while (edades[i]<0 || edades[i]>120){
  36.                 System.out.println("Edad no valida");
  37.                 System.out.println("Introduce edad");
  38.                 edades[i]=Consola.leeInt();
  39.             }
  40.            
  41.            
  42.        }
  43.      
  44.        float r = edadmedia(edades);{
  45.         System.out.println("La media es \n "+r);
  46.        
  47.         int cont = 0;
  48.         for (int i=0; i<edades.length;i++){
  49.            
  50.             if(edades[i]>r){
  51.                 cont++;
  52.             }
  53.         }
  54.      
  55.         System.out.println("La cantidad de edades mayores a la media es\n"+cont);
  56.        
  57.     edadmax = 0;   
  58.       for (int i=0; i<edades.length;i++){
  59.          
  60.           if(edades[i]>edadmax){
  61.               edadmax=edades[i];
  62.           }
  63.       }
  64.      
  65.       System.out.println("La edad maxima es \n"+edadmax);
  66.      
  67.        cont = 0;
  68.      
  69.       for (int i=0; i<edades.length;i++){
  70.          
  71.           if(edades[i]<edadmin){
  72.               edadmin=edades[i];
  73.               cont=1;
  74.           }
  75.               else if ( edades[i] == edadmin )
  76.                   cont++;
  77.          
  78.       }
  79.      
  80.       System.out.println("La edad minima es \n"+edadmin);
  81.       System.out.println("La cantidad de edades minimas son\n"+cont);
  82.  
  83.      
  84.        }
  85.    
  86.     }
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment