Недостижимый код; я не понимаю, почему это недоступно
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)"
я серьезно не могу найти, как это недостижимо, я проверил скобки и все виды, любая помощь или подсказки были бы оценены
2 ответа
Сначала проанализируйте свой код, посмотрите на блок
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
ярлык недоступен
Вы упомянули метку "По умолчанию" после оператора 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 утверждения, разве вы не наблюдаете что-то подозрительное там?
перерыв; Оператор Statement выводит управление из оператора case, и значение по умолчанию никогда не получит шанс выполнить