gpt4 book ai didi

java - 传递方法信息

转载 作者:行者123 更新时间:2023-12-01 12:11:58 25 4
gpt4 key购买 nike

谁能帮我解决这个问题吗?

import java.util.*;
public class PaintCalculator
{
public static void main(String[] args)
{
double length;
double width;
double height;

Scanner input = new Scanner(System.in);

System.out.print("Enter the length in feet: ");
length = input.nextDouble();
System.out.print("Enter the width in feet: ");
width = input.nextDouble();
System.out.print("Enter the height in feet: ");
height = input.nextDouble();

System.out.println();
PtinSqFt(length,width,height);

System.out.println("The Cost of a " + length + "- by " + width + "-foot room with a " + height + "-foot ceilings is " + newAmount + "$");
}

public static double PtinSqFt(double v1, double v2, double v3)
{
double GoP = v1*v2*v3;
double newAmount;
newAmount = GallonsOfPaint(GoP)*32;
System.out.println("The wall area for the room is " + GoP + " Square Feet!");
System.out.println("You will need " + GallonsOfPaint(GoP) + " gallons of paint!");
System.out.println("The Cost of a " + v1 + "- by " + v2 + "-foot room with a " + v3 + "- foot ceilings is " + newAmount + "$");
return newAmount;
}



public static double GallonsOfPaint(double GoP)
{
final double SQFT_OF_RM = 350;
double newgallons = (GoP/SQFT_OF_RM);
return newgallons;

}

}

当我尝试从 PtinSqFt 方法中提取返回信息时,它不会编译?

最佳答案

您需要存储PtinSqFt(length,width,height);的返回值如果您想稍后在 println 中使用它,则在变量中声明。

所以改变这个

PtinSqFt(length,width,height);

double newAmount = PtinSqFt(length,width,height);

它应该可以工作。

关于java - 传递方法信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27217851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com