Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.print("NAME ");
		first_name=scanner.next();
		
		System.out.print("WEIGHT, kg");
		kg=scanner.nextInt();
		
		System.out.print("HEIGHT, m");
		height=scanner.nextDouble();
		
                bmi= kg / (height * height);

        
        System.out.printf("%s %20s %20s %20s", "NAME", "Weight", "Height", "BMI");
        System.out.println();
        System.out.printf("%-10s %12d %21.2f %22.2f",first_name,kg,height,bmi);
        System.out.println();
}

	
	
	
}
}


What I have tried:

how can I make this data to be brought to one table at the end,not so separately,without array. I've had a issues
Posted
Comments
OriginalGriff 24-Nov-20 8:52am    
"I've had a issues"
What issues?

What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.
g.v.d 24-Nov-20 8:58am    
I have no problem in the program itself, I have a problem with making a whole table and not bringing them to me individually
OriginalGriff 24-Nov-20 9:16am    
What have you tried?
Have you considered creating a class to hold a row's worth of info?
Or perhaps a ResultSet?
Richard MacCutchan 24-Nov-20 9:26am    
You need two loops. The first loop should collect the data from the user and save it to a list. The second loop should read the entries in the list and print the results. So the first thing you need to create is a class of BMIEntry, which will hold the details. Then you need a List<BMIEntry> to hold the entries as you create them. So within your first loop:
1. Create a new BMIEntry object
2. get the details from the user and add them to the object
3. Add the object to the List

Then in the second loop:
for each entry in the List, print the details, calculating the BMI value as you do so.
g.v.d 24-Nov-20 10:17am    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900