gpt4 book ai didi

java - 如何在另一个方法中包含返回的字符串 - java

转载 作者:行者123 更新时间:2023-12-01 18:34:38 27 4
gpt4 key购买 nike

这可能是一个非常基本的问题,但由于我只是初学者,这让我感到困惑。我正在尝试将字符串的第一个字母大写,这是我使用以下代码完成的:

public String capitalizeFirstLetter(String product){ 
String productCap = product.substring(0, 1).toUpperCase() + product.substring(1);
return productCap; }

然后将这个大写版本的产品放入字母书写器方法中:

public void writeALetterChallenge(String nameFirst, String nameLast, String city, String    product, String company, double retail, int numItem){ 
UI.println("Dear " + nameFirst);
UI.println(" You have been especially selected from the people of " + city);
UI.println("to receive a special offer for "+ product);
UI.println(productCap + " from " + company + " is a premium brand prodcut and"); UI.printf("retails for $%1.2f" + ". But, " + nameFirst + ",if you order your " + product + "\n", (retail));
UI.println("today, you can purchase it for just $" + (retail - (retail * 0.60)) + ", a saving of 60%!");
UI.println("As a special bonus, just for the " + nameLast + "family, if you order"); UI.println(numItem + " " + product + " today, you will get an additional 10% off - "); UI.println("an amazing price for " + product + " of just $" + (retail - (retail * 0.70)) + "!");
UI.println(" ");
UI.println("Hurry today and send in your order for " + product + " from " + company); UI.println("and make these fantastic savings.");
UI.println(" "); }

但是我的问题是,当我编译时,出现找不到productCap 的错误。所以我显然错过了一些东西。如何从第一个方法中获取 ProductCap 变量并将其包含在第二个方法中?

对此的任何解释都很好,谢谢!

最佳答案

你应该调用你的方法:

UI.println(capitalizeFirstLetter(product) + " from " + compan ...

关于java - 如何在另一个方法中包含返回的字符串 - java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22588756/

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