Created
February 21, 2014 05:43
-
-
Save ltagliaferri/9129424 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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