Java String.replace()不是';工作不正常吗?我做错了什么?

Java String.replace()不是';工作不正常吗?我做错了什么?,java,string,replace,Java,String,Replace,我正在写一个代码来输出“墙上99瓶啤酒”程序。我试着让它说“墙上有一瓶啤酒”,而不是瓶子。我不确定我的代码出了什么问题。任何帮助都将不胜感激 public class BeerOnTheWall { public static void handleCountdown() { int amount = 99; int newamt = amount - 1; String bottles = " bottles"; while(amount != 0

我正在写一个代码来输出“墙上99瓶啤酒”程序。我试着让它说“墙上有一瓶啤酒”,而不是瓶子。我不确定我的代码出了什么问题。任何帮助都将不胜感激

public class BeerOnTheWall {

public static void handleCountdown() {

    int amount = 99;
    int newamt = amount - 1;
    String bottles = " bottles";

        while(amount != 0) {

            if(amount == 1) {
                bottles.replace("bottles", "bottle");
            }

        System.out.println(amount + bottles +" of beer on the wall, "
                + amount + bottles +" of beer! You take one down, pass it around, "
                + newamt + " bottles of beer on the wall!");
        amount--;
        newamt--;



    }



    System.out.println("Whew! Done!");
}

public static void main(String args[]) {
    handleCountdown();  
}


}
我有一个if语句,它假设检查int“amount”是否等于1,然后用“瓶”替换“瓶”

有什么帮助吗

谢谢。

字符串#replace
返回修改后的
字符串
,因此您需要替换:

if(amount == 1) {
    bottles.replace("bottles", "bottle");
}
与:

请参阅。

String#replace
返回修改后的
字符串
,因此需要替换:

if(amount == 1) {
    bottles.replace("bottles", "bottle");
}
与:

请参阅。

String#replace
返回修改后的
字符串
,因此需要替换:

if(amount == 1) {
    bottles.replace("bottles", "bottle");
}
与:

请参阅。

String#replace
返回修改后的
字符串
,因此需要替换:

if(amount == 1) {
    bottles.replace("bottles", "bottle");
}
与:


瞧。

我真不敢相信我错过了!多么简单的错误!非常感谢。真不敢相信我错过了!多么简单的错误!非常感谢。真不敢相信我错过了!多么简单的错误!非常感谢。真不敢相信我错过了!多么简单的错误!非常感谢。