作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这可能是一个非常基本的问题,但由于我只是初学者,这让我感到困惑。我正在尝试将字符串的第一个字母大写,这是我使用以下代码完成的:
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/
我是一名优秀的程序员,十分优秀!