15,611,656 members
1.00/5 (1 vote)
See more:
I have to make a for loop, who has to calculate the BMI of several people. But i dont know how to do it. I only has this. Can someone help me. In java

```import java.util.Scanner;
public class BMI {
public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

String first_name;
int kg;
double height;
double bmi;

for(int i=1; i<=4; i++) {
System.out.println("NAME ");
first_name=scanner.next();

System.out.println("WEIGHT, kg");
kg=scanner.nextInt();

System.out.println("HEIGHT, m");
height=scanner.nextDouble();

System.out.println("BMI");
bmi = kg / (height * height);
}

}
}```

What I have tried:

`I have to make a for loop, who has to calculate the BMI of several people. But i dont know how to do it. I only has this. Can someone help me. In java`
Posted
Updated 23-Nov-20 3:16am

## Solution 1

You already have it. The only bit missing is the display of the final BMI value that you have calculated.

## Solution 2

Quote:
I have to make a for loop, who has to calculate the BMI of several people. But i dont know how to do it. I only has this. Can someone help me.

You have it already. There 1 toll that can show you what is going on, it is the debugger, give it a try.

Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

jdb - The Java Debugger[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.