我正在尝试创建一个简单的程序,在输入指定的数字时输出歌曲的歌词。问题是我的第二种情况不会输出,只会输出第一种情况。当我尝试输出第二种情况时,它仍然输出第一种情况。无论我是否发表两次声明,这仍然会发生。有人可以帮我修改我的代码吗?
这是:
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;
}
}
}
}
当用户键入数字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;
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");
请注意我对编码很陌生,所以请尽量解释最好的编码。如果没有,我仍然可以理解,但无论如何,请简要解释一下你的解决方案。
答案 0 :(得分:2)
更改
uone = input.nextInt();
utwo = input.nextInt();
switch (one){
要
int choice = input.nextInt();
switch (choice)