Можно конечно просто решить через if, но интересно почему не работает так?
package com.javarush.task.task06.task0605;
import java.io.*;
/*
Контролируем массу тела
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bis = new BufferedReader(new InputStreamReader(System.in));
double weight = Double.parseDouble(bis.readLine());
double height = Double.parseDouble(bis.readLine());
Body.calculateMassIndex(weight, height);
}
public static class Body {
public static void calculateMassIndex(double weight, double height) {
double index = weight / (height * height);
String index1 = "Недовес: меньше чем 18.5";
String index2 = "Нормальный: между 18.5 и 25";
String index3 = "Избыточный вес: между 25 и 30";
String index4 = "Ожирение: 30 или больше";
int count1 = index < 18.5 ? 1 : 0;
int count2 = (index >= 18.5 && index < 25) ? 1 : 0;
int count3 = (index >= 25 && index < 30) ? 1 : 0;
int count4 = index >= 30 ? 1 : 0;
int count = count1+count2+count3+count4;
if (count == 1)
System.out.println(index1);
else if (count == 2)
System.out.println(index2);
else if (count == 3)
System.out.println(index3);
else if (count == 4)
System.out.println(index4);
}
}
}