※J.Y Chen 的個人部落格 ※

Just Follow Our Heart And We will shine!

43 瀏覽人次

【程式語言】JAVA的第二堂課 |計算BMI 字串並顯示

Published: in JAVA by .


import java.util.*;

class ch3 {
	public static void main(String[] aru) {
		Scanner myInput = new Scanner(System.in);
		DecimalFormat df = new DecimalFormat("##.0");
		System.out.println("Hello," + aru[0]);
		System.out.print("Your gender:");
		String gender = myInput.nextLine();
		System.out.print("Your height in meter:");
		float height = myInput.nextFloat();
		System.out.print("Your weight in kilogram:");
		float weight = myInput.nextFloat();
		System.out.println("Your BMI is " + df.format((weight)/(height*height)) + "M");
	}
}

©2019 - 2024 Henry Chen