import java.util.Scanner;
public class start {
public static void main(String[] args) {
System.out.println("time to pick a name! type in your desired option");
System.out.println("1: Harry");
System.out.println("2: Billybob");
System.out.println("3: Chuckle brother number 2");
Scanner reader = new Scanner(System.in);
byte input = Byte.parseByte(reader.nextLine());
switch (input) {
case 1:
System.out.println("You have selected Harry");
break;
case 2:
System.out.println("You have selected Billybob");
break;
case 3:
System.out.println("You have selected Chuckle Brother number 2");
break;
default:
System.out.println("Invalid Input");
break;
}
System.out
.println("time to head off. select which path you want to take");
System.out.println("1: the path heading north towards Winterfell");
System.out.println("2: the path heading south, towards the red keep");
System.out
.println("3: the path heading East, towards the Moat Caillin");
byte input2 = Byte.parseByte(reader.nextLine());
switch (input2) {
case 1:
System.out
.println("you start for winterfell. the snows start strong on your way, and you die of exposure. Game Over");
break;
case 2:
System.out
.println("you arrive at the red keep. you are attacked and you lose your money. you are now a beggar in fleebottom");
System.out
.println("A magician offers you a position as his assistant. select which option you take");
System.out.println("1: accept the magicians offer.");
System.out.println("2: kindly decline the magicians offer.");
System.out
.println("3: kill the magician and take his possessions.");
byte input3 = Byte.parseByte(reader.nextLine());
switch (input3) {
case 1:
System.out
.println("the magician takes you to his home, and kills you. Game over.");
break;
case 2:
System.out
.println("the magician is angry, he strikes you, and you die of an infected wound. Game over");
break;
case 3:
System.out
.println("the magician has many expensive potions. You use these to get you into a position within the red keep");
System.out
.println("King Tommen asks you to become a member of the small council. he lets you select your position.. select which option you take");
System.out.println("1: become the master of ships.");
System.out.println("2: become the master of coin.");
System.out.println("3: become the master of whispers.");
byte input5 = Byte.parseByte(reader.nextLine());
switch (input5) {
case 1:
System.out
.println("a storm hits a year later and you lose all of the capitals ships. you are dismissed of your position..");
break;
case 2:
System.out
.println("the capital has no money. the iron bank looks to you for their debt that is owed. you are murdered. Game over!");
break;
case 3:
System.out
.println("you find out secrets of highborn lords. you are a trusted acquaintance to the king.");
System.out
.println("the king is dying. he has no sons. he asks you who he should declare as the next king");
System.out.println("1: you should declare myself");
System.out.println("2: you should declare your uncle.");
System.out
.println("3: you should deide for yourself my king.");
byte input4 = Byte.parseByte(reader.nextLine());
switch (input4) {
case 1:
System.out
.println("the lord insults you at dinner. you lose your temper and walk out. the lord has you killed. Game over.");
break;
case 2:
System.out
.println("the lord accepts your decline. he offers you gold to reconsider, as he has a proposition for you.");
break;
case 3:
System.out
.println("you kill the lord, and take Moat Caillin. you marry the daughter of a highborn.");
break;
default:
System.out.println("invalid input");
}
break;
default:
System.out.println("Invalid Input");
break;
}
break;
default:
System.out.println("invalid input");
}
break;
default:
System.out.println("invalid input");
break;
case 3: {
System.out
.println("You head towards Moat Caillin. the journey is swift and you are greeted by the Lord of Moat Caillin");
System.out
.println("The Lord of Moat Caillin offers your his company for dinner. type in your desired option");
System.out.println("1: accept the lords offer.");
System.out.println("2: kindly decline the lords offer.");
System.out.println("3: kill the lord and take his possessions.");
byte input4 = Byte.parseByte(reader.nextLine());
switch (input4) {
case 1:
System.out
.println("the lord insults you at dinner. you lose your temper and walk out. the lord has you killed. Game over.");
break;
case 2:
System.out
.println("the lord accepts your decline. he offers you gold to reconsider, as he has a proposition for you.");
break;
case 3:
System.out
.println("you kill the lord, and take Moat Caillin. you marry the daughter of a highborn.");
break;
default:
System.out.println("invalid input");
}
break;
Default: System.out.println("Invalid Input");
break;
}
}
}
}
“当它运行时它说线程中的异常”main“java.lang.Error:未解决的编译问题: 无法访问的代码
at start.main(start.java:143)"
我认真无法找到它是如何不合适的,我检查括号和各种各样,任何帮助或提示将不胜感激
答案 0 :(得分:0)
你已经提到过'默认' break语句后的标签,就是问题
case 3: {
System.out
.println("You head towards Moat Caillin. the journey is swift and you are greeted by the Lord of Moat Caillin");
System.out
.println("The Lord of Moat Caillin offers your his company for dinner. type in your desired option");
System.out.println("1: accept the lords offer.");
System.out.println("2: kindly decline the lords offer.");
System.out.println("3: kill the lord and take his possessions.");
byte input4 = Byte.parseByte(reader.nextLine());
switch (input4) {
case 1:
System.out
.println("the lord insults you at dinner. you lose your temper and walk out. the lord has you killed. Game over.");
break;
case 2:
System.out
.println("the lord accepts your decline. he offers you gold to reconsider, as he has a proposition for you.");
break;
case 3:
System.out
.println("you kill the lord, and take Moat Caillin. you marry the daughter of a highborn.");
break;
default:
System.out.println("invalid input");
}
break;
default: System.out.println("Invalid Input");
break;
}
观察最后3个陈述,难道你没有观察到那些可疑的东西吗?
中断;语句将从case语句中取出控制权,默认情况下永远不会有机会执行
答案 1 :(得分:0)
首先,分析你的代码, 看看块
case 3: {
System.out
.println("You head towards Moat Caillin. the journey is swift and you are greeted by the Lord of Moat Caillin");
System.out
.println("The Lord of Moat Caillin offers your his company for dinner. type in your desired option");
System.out.println("1: accept the lords offer.");
System.out.println("2: kindly decline the lords offer.");
System.out.println("3: kill the lord and take his possessions.");
byte input4 = Byte.parseByte(reader.nextLine());
switch (input4) {
case 1:
System.out
.println("the lord insults you at dinner. you lose your temper and walk out. the lord has you killed. Game over.");
break;
case 2:
System.out
.println("the lord accepts your decline. he offers you gold to reconsider, as he has a proposition for you.");
break;
case 3:
System.out
.println("you kill the lord, and take Moat Caillin. you marry the daughter of a highborn.");
break;
default:
System.out.println("invalid input");
}
break;
Default:
System.out.println("Invalid Input");
break;
}
让我们分析这个块,你有什么,是一堆打印语句,然后切换块,然后打破。 break导致tou退出此case语句,因此Default
标签无法访问后的代码