import java.util.Scanner; /** * Calculate the body mass index and the nutritional category for a set of data */ class Solution { /** * Gets data from standard input */ private Scanner input; /** * Start the execution of the solution * @param args Command line arguments */ public static void main(String args[]) { Solution solution = new Solution(); solution.run(); } /** * Run the solution. This method is called from main() */ public void run() { // Create object to read data from standard input input = new Scanner(System.in); // Mientras hayan datos: while ( input.hasNextDouble() ) { // Obtener la masa en kilogramos double mass = input.nextDouble(); // Obtener la altura en centimetros double heightCm = input.nextDouble(); // Informar la masa, la altura en centrimetros, y el bmi System.out.printf("%6.2f %6.2f ", mass, heightCm); // Si masa > 1000 o masa <= 0 o altura <= 0 o altura > 300cm if ( mass > 1000.0 || mass <= 0.0 || heightCm <= 0.0 || heightCm > 300.0 ) { // Informar datos invalidos System.out.println("invalid data"); } else { // Los datos son validos // Convertir la altura a metros double heightMeters = heightCm / 100.0; // Calcular el indice de masa corporal (bmi) double bodyMassIndex = mass / (heightMeters * heightMeters); // Informar la masa, la altura en centrimetros, y el bmi System.out.printf("%5.2f ", bodyMassIndex); // Imprimir el estado nutricional de acuerdo a los rangos de la OMC if ( bodyMassIndex < 18.5 ) { // Informar infrapeso System.out.println("underweight"); } if ( bodyMassIndex >= 18.5 && bodyMassIndex < 25.0 ) { // Informar normal System.out.println("normal"); } if ( bodyMassIndex >= 25.0 && bodyMassIndex < 30.0 ) { // Informar sobrepeso System.out.println("overweight"); } if ( bodyMassIndex >= 30.0 ) { // Informar obesidad System.out.println("obese"); } } } // Close the standard input input.close(); } }