刚开始接触Java时间不久,谢谢各位帮忙。
我想要得到的结果是:输入身高和体重,然后算出来exp是否合理,谢谢,
package forth;
import java.io.*;
public class Person {
float weight;
float height;
String check()
{
float exp = weight/(height*height);
if(exp<18)
return "you are a little slim";
else if(exp>=25)
return "you are a little fat";
else
return "comfortable.";
}
public void setWeight(float weight)
{
this.weight = weight;
}
public void setHeight(float height)
{
this.height = height;
}
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入身高:");
try{
float h = Integer.parseInt(br.readLine());
}
catch(IOException e){}
System.out.println("请输入体重:");
try{
float w = Integer.parseInt(br.readLine());
}
catch(IOException e){}
p.setHeight(h);//这个地方我想把前面从键盘读入的h传进来,该怎么写
p.setWeight(w);
p.check();
}
}
你的p从哪里来的。类里面写个构造函数,new对象的时候把参数传进去。