[Solved] find the min and avg of student if it exist show the name of the student


Try to add a for loop to calcolate the sum of ages like this:

    for(i=0;i<age.length;i++){
        sum+=age[i];
      }

And take out this below block out of for loop:

  avg= sum/age.length;
  System.out.println("the avarage of all Students are :"+avg);
  System.out.println("the minimum age of all Students : "+min);

Like this:

  public static void main(String[] args) {
    // TODO code application logic here

   int[] age = new int []{21,20,19,18,18,};
   String name [] = {"sofia","maria","john","Petra","mark"};
  int sum = 0;
  int avg;
  int min=age[0];
  int i;
  int counter=0;
  for(i=0;i<age.length;i++){
  if(age[i]<min ) {
     min=age[i];

   }
 }
  for(i=0;i<age.length;i++){
        sum+=age[i];
      }

  avg= sum/age.length;
  System.out.println("the avarage of all Students are :"+avg);
  System.out.println("the minimum age of all Students : "+min);
  for(i=0;i<age.length;i++){
  if (age[i] == min ) {
          System.out.println("the minimum age of all Students  : "+name[i]); 
        }

     }
    }
   } 

Output:

 the avarage of all Students are :19
 the minimum age of all Students : 18
 the minimum age of all Students  : Petra
 the minimum age of all Students  : mark

solved find the min and avg of student if it exist show the name of the student