Java 为什么当我运行代码时我的数字不显示

Java 为什么当我运行代码时我的数字不显示,java,Java,您将自动播放著名歌曲“99瓶XXX在墙上”。你将打印这首歌的所有99首诗的歌词。使用循环!如果你不知道歌词,可以用谷歌搜索 该计划应: 询问用户的年龄 如果用户是21岁或以上,询问他们是否喜欢啤酒或苏打水 a。如果他们不到21岁,或者他们更喜欢苏打水,那么歌词是“墙上有99瓶苏打水” b。如果他们超过21岁,那就是“99瓶啤酒” 必须使用WHILE循环,并且计数器变量必须是print语句的一部分 所以第一节是: 墙上有99瓶苏打水 99瓶苏打水 如果其中一个瓶子从墙上掉下来 墙上挂着98瓶苏打

您将自动播放著名歌曲“99瓶XXX在墙上”。你将打印这首歌的所有99首诗的歌词。使用循环!如果你不知道歌词,可以用谷歌搜索

该计划应:

  • 询问用户的年龄

  • 如果用户是21岁或以上,询问他们是否喜欢啤酒或苏打水

    a。如果他们不到21岁,或者他们更喜欢苏打水,那么歌词是“墙上有99瓶苏打水”

    b。如果他们超过21岁,那就是“99瓶啤酒”

  • 必须使用WHILE循环,并且计数器变量必须是print语句的一部分

  • 所以第一节是:

    墙上有99瓶苏打水

    99瓶苏打水

    如果其中一个瓶子从墙上掉下来

    墙上挂着98瓶苏打水

  • 最后一节:

    墙上有一瓶苏打水

    一瓶苏打水

    如果那瓶汽水从墙上掉下来

    墙上没有汽水瓶

试想一下,你需要在循环中添加什么内容来打印最后一段歌词稍有不同的歌词

//这是我的密码。当我运行它时,瓶子的数量从12开始,而不是99 我该如何解决这个问题

Scanner user = new Scanner(System.in);

           int age, beverage;


           System.out.println("Please type in your age");
           age = user.nextInt();

           user.nextLine();
           System.out.println("Would you like soda or beer? soda=1 beer=2");
           beverage = user.nextInt();

        if(age<21 || beverage==1)
           {
           int bottles = 99;
            while( 1< bottles){
                System.out.println(bottles+" of soda on the wall");
                System.out.println(bottles+" bottles of soda");
                System.out.println("If one of those bottles should fall off the wall");
                bottles--;
                System.out.println("..."+bottles+" bottles of soda on the wall");
            if(bottles==1){
                System.out.println(bottles+" of soda on the wall");
                System.out.println(bottles+" bottles of soda");
                System.out.println("If that lone bottle of soda should fall off the wall");
                System.out.println("No bottles of soda on the wall");
            }
        }
    }
        if(age>=21 && beverage == 2)
        {
            int bottles=99;
            while(1< bottles){
                System.out.println(bottles+" of beer on the wall");
                System.out.println(bottles+" bottles of beer");
                System.out.println("If one of those bottles should fall off the wall");
                bottles--;
                System.out.println("..."+bottles+" bottles of beer on the wall");
            if(bottles==1){
                System.out.println(bottles+" of beer on the wall");
                System.out.println(bottles+" bottles of beer");
                System.out.println("If that lone bottle of beer should fall off the wall");
                System.out.println("No bottles of beer on the wall");
            }
        }
    }

        }
    }
Scanner user=新扫描仪(System.in);
国际食品、饮料;
System.out.println(“请输入您的年龄”);
age=user.nextInt();
user.nextLine();
System.out.println(“您想要苏打水还是啤酒?苏打水=1啤酒=2”);
饮料=user.nextInt();
如果(年龄=21岁&饮料=2岁)
{
整数=99;
而(1瓶以下){
系统输出打印LN(墙上的啤酒瓶+);
System.out.println(瓶+瓶啤酒);
System.out.println(“如果其中一个瓶子从墙上掉下来”);
瓶子--;
System.out.println(“…”+瓶+瓶啤酒挂在墙上”);
如果(瓶==1){
系统输出打印LN(墙上的啤酒瓶+);
System.out.println(瓶+瓶啤酒);
如果那瓶啤酒从墙上掉下来;
System.out.println(“墙上没有啤酒瓶”);
}
}
}
}
}

您的代码确实从99瓶开始打印。如果您只看到最后12个瓶子,则输出控制台存在问题。尝试进一步向上滚动,或尝试使用其他控制台,或尝试将其重定向到文件(将“>output.txt”添加到命令行调用中,然后检查output.txt的内容)。

在(1您的编码方式存在问题。如果您想向有经验的程序员学习,建议将此代码发布在codereview.stackexchange.com上。循环直到1<瓶并检查每个循环的条件没有意义,循环直到2(包括)然后打印最后一行。不要重复所有的
println
语句,只说“beer”而不是“soda”,你可以将这一个单词放入
字符串
变量中,并根据该变量打印消息:
瓶子+“of”+饮料+“on the wall”
。这是一个注释,不是一个完整的答案!