hi, why my code when i try to calculate BMI every time the answer equal 0.0 and can't get the right answer?     package a; import java.util.*; public class a {   public static void main(String []args){ Scanner sc=new Scanner(System.in); label: System.out.println("Enter the number of cities"); int noOfcities,nPerson; noOfcities=sc.nextInt(); int under=0,obese=0,normal=0,over=0,c_under=0,c_obese=0,c_normal=0,c_over=0; double p_under,p_over,p_obese,p_normal; double max_normal=0.0,max_obese=0.0,min_under=100.0; String name,b_city="None",w_city="None",u_city="None",cat; int mass,height; while ( noOfcities<6){ System.out.println("erro"); System.out.println("Enter the number of cities"); noOfcities=sc.nextInt(); }int i=0; while (i=10) for(int j=0;j=18.5 && bmi<25) { cat="normal"; c_normal++; } else if(bmi>=25 && bmi<30) { cat="overweight"; c_over++; } else { cat="obese"; c_obese++; } System.out.println("The person has a BMI of "+bmi+" and belongs to category "+cat); } under+=c_under; over+=c_over; normal+=c_normal; obese+=c_obese; p_under=(under/nPerson)*100; p_normal=(normal/nPerson)*100; p_over=(over/nPerson)*100; p_obese=(obese/nPerson)*100; System.out.println("For the city "+name+" category wise breakup is:"); System.out.println("Number of people who are Underweight: "+under+ ", Percentage is: "+p_under); System.out.println("Number of people who are Normal: "+normal+ ", Percentage is: "+p_normal); System.out.println("Number of people who are Overweight: "+over+ ", Percentage is: "+p_over); System.out.println("Number of people who are Obese: "+obese+ ", Percentage is: "+p_obese); if(p_normal>max_normal) { max_normal=p_normal; b_city=name; } if(p_obese>max_obese) { max_obese=p_obese; w_city=name; } if(p_under

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

hi, why my code when i try to calculate BMI every time the answer equal 0.0 and can't get the right answer?

 

 

package a;
import java.util.*;
public class a {

 


public static void main(String []args){

Scanner sc=new Scanner(System.in);
label:

System.out.println("Enter the number of cities");
int noOfcities,nPerson;
noOfcities=sc.nextInt();

int under=0,obese=0,normal=0,over=0,c_under=0,c_obese=0,c_normal=0,c_over=0;
double p_under,p_over,p_obese,p_normal;
double max_normal=0.0,max_obese=0.0,min_under=100.0;
String name,b_city="None",w_city="None",u_city="None",cat;
int mass,height;

while ( noOfcities<6){
System.out.println("erro");
System.out.println("Enter the number of cities");

noOfcities=sc.nextInt();

}int i=0;
while (i<noOfcities){
i++;
System.out.println("Enter the name of city");
name=sc.next();
System.out.println("Enter the number of persons");
nPerson=sc.nextInt();
while (nPerson<10)
{System.out.println("eror");
System.out.println("Enter the number of persons");
nPerson=sc.nextInt();
}
c_under=0;c_obese=0;c_normal=0;c_over=0;
if(nPerson>=10)
for(int j=0;j<nPerson;j++)
{
System.out.println("Enter the mass and height");
mass=sc.nextInt();
height=sc.nextInt();
while (mass<1||height<1){
System.out.println("error");

System.out.println("Enter the mass and height");
mass=sc.nextInt();
height=sc.nextInt();

}

double bmi = mass / ( height * height) ;


if(bmi<18.5)
{
cat="underweight";
c_under++;
}
else if(bmi>=18.5 && bmi<25)
{
cat="normal";
c_normal++;
}
else if(bmi>=25 && bmi<30)
{
cat="overweight";
c_over++;
}
else
{
cat="obese";
c_obese++;
}
System.out.println("The person has a BMI of "+bmi+" and belongs to category "+cat);
}

under+=c_under;
over+=c_over;
normal+=c_normal;
obese+=c_obese;


p_under=(under/nPerson)*100;
p_normal=(normal/nPerson)*100;
p_over=(over/nPerson)*100;
p_obese=(obese/nPerson)*100;

System.out.println("For the city "+name+" category wise breakup is:");
System.out.println("Number of people who are Underweight: "+under+ ", Percentage is: "+p_under);
System.out.println("Number of people who are Normal: "+normal+ ", Percentage is: "+p_normal);
System.out.println("Number of people who are Overweight: "+over+ ", Percentage is: "+p_over);
System.out.println("Number of people who are Obese: "+obese+ ", Percentage is: "+p_obese);

if(p_normal>max_normal)
{
max_normal=p_normal;
b_city=name;
}

if(p_obese>max_obese)
{
max_obese=p_obese;
w_city=name;
}

if(p_under<min_under)
{
min_under=p_under;
u_city=name;
}

}
System.out.println("tttt");



System.out.println("Number of Cities are: "+noOfcities);
System.out.println("Best city is "+b_city);
System.out.println("Worst city is "+w_city);
System.out.println("The city which has the minimum percent of people in underweight category is "+u_city);

}

Enter the number of cities
Enter the name of city
cityl
Enter the number of persons
10
Enter the mass and height
88
178
The person has a BMI of 0.0 and belongs to category underweight
Enter the mass and height
Transcribed Image Text:Enter the number of cities Enter the name of city cityl Enter the number of persons 10 Enter the mass and height 88 178 The person has a BMI of 0.0 and belongs to category underweight Enter the mass and height
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY