- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个简单的程序,当输入指定的数字时输出歌曲的歌词。问题是我的第二种情况不会输出,而只输出第一种情况。当我尝试输出第二种情况时,它仍然输出第一种情况。不管我是否做了两个 while 语句,这种情况仍然会发生。有人可以帮我修复我的代码吗?
这里是:
import java.util.Scanner;
public class Lyrics {
public static void main (String args[]){
Scanner input = new Scanner (System.in);
int one, two, uone, utwo;
one = 1;
two = 2;
System.out.println("Welcome to the Lyrics Finder!");
System.out.println("Press the number beside the song to see the lyrics!");
System.out.println("1) Thank For The Memories - Fall Out Boy");
System.out.println("2) Take Me To Church - Hozier");
uone = input.nextInt();
utwo = input.nextInt();
switch (one){
case 1:
//code goes here for option 1
System.out.println("");
System.out.println("Thank For The Memories - Fall Out Boy Lyrics");
System.out.println(" == ");
System.out.println("I'm gonna make it bend and break");
System.out.println("Say a prayer but let the good times roll");
System.out.println("In case God doesn't show");
System.out.println("(Let the good times roll, let the good times roll)");
System.out.println("And I want these words to make things right");
System.out.println("But it's the wrongs that make the words come to life");
System.out.println("Who does he think he is?");
System.out.println("Who does he think he is?");
System.out.println("Better put your fingers back to the keys");
//continue song here
break;
case 2:
//retype all code her for it to reset
System.out.println("");
System.out.println("Take Me To Church - Hozier");
System.out.println(" == ");
System.out.println("My lover's got humour, She's the giggle at a funeral");
System.out.println("Knows everybody's disapproval, I should've worshipped her sooner");
System.out.println("If the heavens ever did speak, She's the last true mouthpiece");
System.out.println("Every Sunday's getting more bleak, A fresh poison each week");
System.out.println("We were born sick you heard them say it");
System.out.println("My church offers no absolutes, She tells me Worship in the bedroom");
break;
}
while (uone == one){
System.out.println("");
System.out.println("<-=LYRICS ABOVE=->");
System.out.println("<-=OPTIONS=->");
System.out.println("Press the number beside the song to see the lyrics!");
System.out.println("1) Thank For The Memories - Fall Out Boy");
System.out.println("2) Take Me To Church - Hozier");
uone = input.nextInt();
utwo = input.nextInt();
switch (one){
case 1:
//code goes here for option 1
System.out.println("");
System.out.println("Thank For The Memories - Fall Out Boy Lyrics");
System.out.println(" == ");
System.out.println("I'm gonna make it bend and break");
System.out.println("Say a prayer but let the good times roll");
System.out.println("In case God doesn't show");
System.out.println("(Let the good times roll, let the good times roll)");
System.out.println("And I want these words to make things right");
System.out.println("But it's the wrongs that make the words come to life");
System.out.println("Who does he think he is?");
System.out.println("Who does he think he is?");
System.out.println("Better put your fingers back to the keys");
//continue song here
break;
case 2:
//retype all code her for it to reset
System.out.println("");
System.out.println("Take Me To Church - Hozier");
System.out.println(" == ");
System.out.println("My lover's got humour, She's the giggle at a funeral");
System.out.println("Knows everybody's disapproval, I should've worshipped her sooner");
System.out.println("If the heavens ever did speak, She's the last true mouthpiece");
System.out.println("Every Sunday's getting more bleak, A fresh poison each week");
System.out.println("We were born sick you heard them say it");
System.out.println("My church offers no absolutes, She tells me Worship in the bedroom");
break;
}
}
}
}
当用户输入数字一时,应该输出:
System.out.println("");
System.out.println("Thank For The Memories - Fall Out Boy Lyrics");
System.out.println(" == ");
System.out.println("I'm gonna make it bend and break");
System.out.println("Say a prayer but let the good times roll");
System.out.println("In case God doesn't show");
System.out.println("(Let the good times roll, let the good times roll)");
System.out.println("And I want these words to make things right");
System.out.println("But it's the wrongs that make the words come to life");
System.out.println("Who does he think he is?");
System.out.println("Who does he think he is?");
System.out.println("Better put your fingers back to the keys");
//continue song here
break;
while (uone == one){
System.out.println("");
System.out.println("<-=LYRICS ABOVE=->");
System.out.println("<-=OPTIONS=->");
System.out.println("Press the number beside the song to see the lyrics!");
System.out.println("1) Thank For The Memories - Fall Out Boy");
System.out.println("2) Take Me To Church - Hozier");
当用户输入数字 2 时,应该输出:
System.out.println("");
System.out.println("Take Me To Church - Hozier");
System.out.println(" == ");
System.out.println("My lover's got humour, She's the giggle at a funeral");
System.out.println("Knows everybody's disapproval, I should've worshipped her sooner");
System.out.println("If the heavens ever did speak, She's the last true mouthpiece");
System.out.println("Every Sunday's getting more bleak, A fresh poison each week");
System.out.println("We were born sick you heard them say it");
System.out.println("My church offers no absolutes, She tells me Worship in the bedroom");
break;
while (uone == one){
System.out.println("");
System.out.println("<-=LYRICS ABOVE=->");
System.out.println("<-=OPTIONS=->");
System.out.println("Press the number beside the song to see the lyrics!");
System.out.println("1) Thank For The Memories - Fall Out Boy");
System.out.println("2) Take Me To Church - Hozier");
请注意,我对编码非常陌生,因此请尽力解释。如果没有,我仍然可以理解,但无论如何,请简要解释一下您的解决方案。
最佳答案
改变
uone = input.nextInt();
utwo = input.nextInt();
switch (one){
至
int choice = input.nextInt();
switch (choice)
关于Java:为什么我的 while 语句不适用于我的案例 2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29860002/
这个问题在这里已经有了答案: Oracle: merging two different queries into one, LIKE & IN (1 个回答) 8年前关闭。 我有以下代码: case
我查阅过此页面:http://dev.mysql.com/doc/refman/5.1/en/case.html以及这个,但无法获得一个简单的程序来工作...... 更新:为了明确我想要做什么:我想从
有什么办法可以优化下面的查询吗? SELECT DATE_FORMAT(a.duedate,'%d-%b-%y') AS dte, duedate, SUM(CASE WHEN (typeofnoti
我进退两难,以下 SQL 查询的结果是什么以及它是如何工作的: SELECT ... CASE WHEN (a.FIELD=1 AND b.FIELD=2) THEN 1 WHEN
问题:输入年,月,打印对应年月的日历。 示例: 问题分析: 1,首先1970年是Unix系统诞生的时间,1970年成为Unix的元年,1970年1月1号是星期四,现在大多的手机的日历功能只能显
**摘要:**介绍了Angular中依赖注入是如何查找依赖,如何配置提供商,如何用限定和过滤作用的装饰器拿到想要的实例,进一步通过N个案例分析如何结合依赖注入的知识点来解决开发编程中会遇到的问题。 本
我想拥有自动伴侣类apply case 类的构造函数来为我执行隐式转换,但无法弄清楚如何这样做。我到处搜索,我能找到的最接近的答案是 this问题(我将解释为什么它不是我在下面寻找的)。 我有一个看起
您好,我已经浏览了“多列案例”问题,但没有看到与此相同的内容,所以我想我应该问一下。 基本上我有两个我想要连接的表(都是子查询的结果)。它们具有相同的列名称。如果我加入他们的 ID 和 SELECT
我发现了一些类型推断的非直觉行为。因此,语义等效代码的工作方式不同,具体取决于编译器推断出的有关函数返回类型的信息。当您在最小单元测试中重现此案例时,或多或少会清楚发生了什么。但我担心在编写框架代码时
CREATE TABLE test ( sts_id int , [status1] int , [status2] int , [status3] int , [status4] int ) INS
我有以下声明: SELECT Dag AS Dag, CASE Jaar WHEN 2013 THEN Levering END AS '2013', CASE
我想做的是为所有高于平均时间、平均时间和低于平均时间的游乐设施获取平均tip_portion。所以返回3行。当我运行它时,它显示: ERROR: missing FROM-clause entry
我正在尝试设置一个包含以下字段的报告: 非常需要报告来显示日期、该日期内的总记录(因此我按日期分组),然后按小时计算 12 小时工作日(从上午 8 点到晚上 8 点)我需要计算记录在这些时间内出现的时
我有这个查询 SELECT users.name FROM users LEFT JOIN weapon_stats ON users.id = weapon_stats.zp_id WHERE we
我正在尝试按收视率等级获取不同视频的计数。我有下表: vid_id views 1 6 1 10 1 900 2 850 2 125000
假设我有一个如下所示的 SQL 语句: select supplier, case when platform in (5,6) then 'mobile' when p
我有一个表测试 TestNumber (int primary key) InactiveBitwise (int) 我执行以下命令: UPDATE tests SET CASE WH
我有一个像这样的表(name=expense): id amount date 1 -1687 2014-01-02 00:00:00.0 2 11000 2014-01-02 0
我有一个 multimap 定义 typedef std::pair au_pair; //vertices typedef std::pair acq_pair; //ch qlty specifi
我有一个有点像枚举的类,它的每个实例都有一个唯一的 int 值,该值从 0 开始并在每个新实例时递增。 class MyEnumLikeClass { static int NextId =
我是一名优秀的程序员,十分优秀!