Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. class Main {
  3.  
  4. /*reads and returns a double from the keyboard*/
  5. public static double readDouble(String prompt){
  6. System.out.println(prompt);
  7. java.util.Scanner keyboard = new java.util.Scanner(System.in);
  8. return keyboard.nextDouble();
  9. }
  10.  
  11.  
  12.  
  13. /*bmiCalc method takes double height and double weight as parameters,
  14. calculates the BMI using the formula above ( bmi = weight/(height * height) ) and returns the bmi as a double.*/
  15.  
  16. public static double b2mb(double b){
  17.  
  18. //Your code here
  19. double b2mb = b/1000000;
  20.  
  21. return b2mb;
  22.  
  23.  
  24. }
  25.  
  26. /*main method that calls readDouble twice to ask you your height and weight,
  27. passes the values to bmiCalc, and prints out the returned double value of bmi.*/
  28.  
  29.  
  30. public static void main(String[] args) {
  31.  
  32. //Your code here
  33. DecimalFormat df = new DecimalFormat("#,###,##0.00");
  34. double bite = readDouble ("How many bytes do you want to convert to Megabytes?");
  35. double b2mb = b2mb(bite);
  36. System.out.println(bite + " bytes is " + df.format(b2mb) + " Megabytes");
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement