Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Ejercicio1;
- import java.io.IOException;
- public class ej1 {
- static float edadmedia(int[] edades){
- int mediaed = 0;
- for (int i=0 ; i<edades.length;i++){
- mediaed=mediaed+ edades[i];
- }
- return mediaed / edades.length;
- }
- public static void main(String[] args) throws IOException {
- // TODO Auto-generated method stub
- int[]edades=new int[10];
- int edadmax=-100;
- int edadmin=240;
- for (int i=0; i<edades.length;i++){
- System.out.println("Introduce edad");
- edades[i]=Consola.leeInt();
- while (edades[i]<0 || edades[i]>120){
- System.out.println("Edad no valida");
- System.out.println("Introduce edad");
- edades[i]=Consola.leeInt();
- }
- }
- float r = edadmedia(edades);{
- System.out.println("La media es \n "+r);
- int cont = 0;
- for (int i=0; i<edades.length;i++){
- if(edades[i]>r){
- cont++;
- }
- }
- System.out.println("La cantidad de edades mayores a la media es\n"+cont);
- edadmax = 0;
- for (int i=0; i<edades.length;i++){
- if(edades[i]>edadmax){
- edadmax=edades[i];
- }
- }
- System.out.println("La edad maxima es \n"+edadmax);
- cont = 0;
- for (int i=0; i<edades.length;i++){
- if(edades[i]<edadmin){
- edadmin=edades[i];
- cont=1;
- }
- else if ( edades[i] == edadmin )
- cont++;
- }
- System.out.println("La edad minima es \n"+edadmin);
- System.out.println("La cantidad de edades minimas son\n"+cont);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment