Skip to content

Instantly share code, notes, and snippets.

@ltagliaferri
Created February 21, 2014 05:43
Show Gist options
  • Save ltagliaferri/9129424 to your computer and use it in GitHub Desktop.
Save ltagliaferri/9129424 to your computer and use it in GitHub Desktop.
import java.io.*;
public class BMICalculator {
public static void main(String[] args) {
int i = 100;
String s1 = getInput("Your weight in kg: ");
String s2 = getInput("Your height in cm: ");
System.out.println("Your weight: " + (s1) + " kg");
System.out.println("Your height: " + (s2) + " cm");
double d1 = Double.parseDouble(s1);
double d2 = Double.parseDouble(s2);
double result = d1 / ((d2 / i) * (d2 / i));
System.out.println("Your BMI: " + result);
}
private static String getInput(String prompt) {
BufferedReader stdin = new BufferedReader(
new InputStreamReader(System.in));
System.out.print(prompt);
System.out.flush();
try {
return stdin.readLine();
} catch (Exception e) {
return "Error: " + e.getMessage();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment