title: Adding up variables in a for loop
body: <p>HI i am making a code where you can type in how many people you want and see their BMI, the thing is i want my code to sum up the total BMI of all the people and then dividing it with the total amount of people typed in.</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Main {
  
      public static double calculate(int weight, int height) {
          weight = 100*100*weight;
          height = height * height;                                       
          return weight / height;
      }
      public static void main(String[] args) {
  
          int sum = 0;
          System.out.println("Enter numbers here");
          Scanner people = new Scanner((new Scanner(System.in)).nextLine());     
          while (people.hasNextInt()) {
              sum += people.nextInt();
          }
  
          for (int x =1; x &lt;= sum; x++) {
  
  
              Scanner scanner = new Scanner(System.in);
              System.out.println("hur lång är du i cm?");              
              int height = scanner.nextInt();
              System.out.println("hur tung är du i kg?");                 
              int weight = scanner.nextInt();
  
              double BMI = calculate(weight, height);                    
              System.out.println(BMI);
  
              System.out.println(+x);
              if (x == sum) {
                  break;
              }
          }
      }
  }
  </code></pre>