主要方法要求:
determineFever方法要求的内容:
我的主要方法:
String myName;
double myTemperature;
System.out.print("\nWhat is your name? ");
myName = readit.next();
System.out.print("\nWhat is your body temperature? ");
myTemperature = readit.nextDouble();
determineFever();
确定发烧方法:
public static void determineFever() {
String message;
if (bodyTemperature <= 98.6) {
message = "Hello " + yourName + ", you have no fever. You may go to the movies.";
} // end if
else {
message = "Hello " + yourName + ", you have a fever. Take some aspirin.";
} // end else
System.out.println(message);
} // end determineFever method
答案 0 :(得分:1)
将您的方法更改为:
public static void determineFever(double bodyTemp, String name)
{
String message;
if (bodyTemp <= 98.6)
{
message = "Hello " + name + ", you have no fever. You may go to the movies.";
} // end if
else
{
message = "Hello " + name + ", you have a fever. Take some aspirin.";
} // end else
System.out.println(message);
} // end determineFever method
然后,在主要内容中,将determineFever();
更改为determineFever(bodyTemperature, yourName);
喜欢这个。我强烈建议在方法中用不同的名称引用这些变量(编辑:我在上面的代码块中更改了它们)。此外,我个人的偏好是将退货类型更改为String
并返回message
并将其打印在main
。
答案 1 :(得分:0)
我认为你在问如何将值传递给函数。这是通过向函数添加parameters
来完成的,如下所示:public static void determinFever(String yourName, double bodyTemperature){
。然后在main
函数中添加determineFever(myName, myTemperature);