第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

調(diào)用帶有參數(shù)的方法到另一個方法

調(diào)用帶有參數(shù)的方法到另一個方法

慕勒3428872 2021-08-13 16:40:18
我試圖弄清楚如何,或者是否可以調(diào)用一個包含參數(shù)的方法。我想在 costForPaint 方法中使用 requiredPaint 方法。(代碼已簡化):public class job {public static void main(String[] args) {    int rooms = 1;    double squareFeet = 0;    double totalSquareFeet = 115;    totalSquareFeet = squareFeet + totalSquareFeet;    }requiredPaint(totalSquareFeet);//i want to use the totalSquareFeet in this method, this is why it is calledpublic static double requiredPaint(double totalSquareFeet) {    double totalPaint = totalSquareFeet / 115;    return totalPaint;}public static double costForPaint() {    double paintCost = 2;    //shows error where required paint is    double totalPaintCost = requiredPaint() * paintCost;    return totalPaintCost;}
查看完整描述

3 回答

?
RISEBY

TA貢獻(xiàn)1856條經(jīng)驗 獲得超5個贊

如果要在costPaint方法中使用requiredPaint方法,則需要強(qiáng)制向 requiredPaint 方法發(fā)送雙參數(shù)?,F(xiàn)在這完全取決于您將如何實現(xiàn)您的功能。


您可以將 double 類型的參數(shù)添加到您的 costForPaint 方法中,如下所示:


public static double costForPaint(double totalSquareFeet) {


    double paintCost = 2;


    //shows error where required paint is

    double totalPaintCost = requiredPaint(totalSquareFeet) * paintCost;


    return totalPaintCost;

}


查看完整回答
反對 回復(fù) 2021-08-13
?
楊__羊羊

TA貢獻(xiàn)1943條經(jīng)驗 獲得超7個贊

你的代碼應(yīng)該像-


public static double costForPaint() {


     double paintCost = 2;

     double totalPaint = 15;//any number you want to initialize in totalPaint 


     double totalPaintCost = requiredPaint(totalPaint) * paintCost;


     return totalPaintCost;

}

您收到錯誤是因為 requiredPaint() 是一個參數(shù)化方法,并且您沒有在其中提供任何參數(shù)。


查看完整回答
反對 回復(fù) 2021-08-13
?
慕蓋茨4494581

TA貢獻(xiàn)1850條經(jīng)驗 獲得超11個贊

1> 在 Java 中,如果您已經(jīng)向方法聲明了一個參數(shù),則必須傳遞該參數(shù)(空值或某個值)。這是一個可以根據(jù)您的要求完成的流程。


2> 你也不能在類塊中調(diào)用方法。所以我刪除了requiredPaint(totalSquareFeet);


public class job {

    public static void main(String[] args) {

        int rooms = 1;

        double squareFeet = 0;

        double totalSquareFeet = 115;

        totalSquareFeet = squareFeet + totalSquareFeet;

        costForPaint(totalSquareFeet);

    }


    //i want to use the totalSquareFeet in this method, this is why it is called

    public static double requiredPaint(double totalSquareFeet) {

        double totalPaint = totalSquareFeet / 115;

        return totalPaint;

    }


    public static double costForPaint(double totalSquareFeet) {


        double paintCost = 2;


        //shows error where required paint is

        double totalPaintCost = requiredPaint(totalSquareFeet) * paintCost;


        return totalPaintCost;

    }

}


查看完整回答
反對 回復(fù) 2021-08-13
  • 3 回答
  • 0 關(guān)注
  • 227 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號