Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BMI {
- public static void main(String []args) {
- Scanner scan = new Scanner(System.in);
- char goAgain;
- String name;
- double weight, height, bmi;
- do {
- System.out.print("How many entries? ");
- int numOfEntries = scan.nextInt();
- while (numOfEntries < 1) {
- System.out.println("Invalid entry.");
- System.out.print("How many entries? ");
- numOfEntries = scan.nextInt();
- }
- String[] entryName = new String[numOfEntries];
- double[] entryWeight = new double[numOfEntries];
- double[] entryHeight = new double[numOfEntries];
- for (int i = 0; i < numOfEntries; i++) {
- System.out.print("Enter name of entry: ");
- name = scan.next();
- entryName[i] = name;
- System.out.print("Enter your weight in lbs. ");
- weight = scan.nextDouble();
- while (weight < 0) {
- System.out.print("Enter weight again! ");
- weight = scan.nextDouble();
- }
- entryWeight[i] = weight;
- System.out.print("Enter your height in inches. ");
- height = scan.nextDouble();
- while (height < 0) {
- System.out.print("Enter height again! ");
- height = scan.nextDouble();
- }
- entryHeight[i] = height;
- }
- for (int j = 0; j < numOfEntries; j++) {
- System.out.printf("\nName: %s \nHeight: %,.2f inches \nWeight: %,.2f lbs \nBMI: " +
- "%,.2f\n",
- entryName[j], entryHeight[j], entryWeight[j], (entryWeight[j] * 703) / (Math.pow(2, entryHeight[j])));
- }
- System.out.print("\nGo again? ");
- goAgain = scan.next().charAt(0);
- } while (goAgain == 'y' || goAgain == 'Y');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement