我想这大概是你要的功能吧?但我不知道你看的是什么网页教学只能看你打出来的
code做更改。
import java.util.Scanner;
package pratice;
public class prac_ch03
public static void main(String [] args){
Scanner scanner = new Scanner(System.in);
float height;
float weight;
System.out.println("Please input your height:");
height = scanner.nextFloat();
System.out.println("Please input your weight:");
weight = scanner.nextFloat();
System.out.println("Your BMI is :" + weight/(height*height));
}
}
※ 引述《ProGramE (SP_one)》之铭言:
: 我是在 Eclipse 编辑 使用 java.io 却发生问题 直接复制网络上的教学也是无法执行?
: 以下是我所编译的
: package pratice;
: import java.io.*;
: public class prac_ch03
: {
: public static void main(String args[])throws IOException
: {
: float height;
: float weight;
: System.out.println("Please input your height.");
: height = keyin.readLine();
: System.out.println("Please input your weight.");
: weight = keyin.readLine();
: System.out.println("Your BMI is :" + weight/(height*height));
: }
: }
: 执行出现:
: Exception in thread "main" java.lang.Error: Unresolved compilation problems:
: keyin cannot be resolved
: keyin cannot be resolved
: at pratice.prac_ch03.main(prac_ch03.java:13)
: 请问是我忽略什么步骤以至于如此吗?
: 在网络上寻找都找不到解答
: 麻烦各位!