Java 不要在循环卡滞时执行此操作

Java 不要在循环卡滞时执行此操作,java,do-while,Java,Do While,我正在尝试为一个项目制作skyrim的一部分,但似乎无法修复此do/while循环。我觉得我一直盯着这个问题看,却没有注意到它。 问题:我运行程序,它到达标题,它询问您是否要播放(y/n),它检查输入的键是否为“y”或“n”,如果不是,程序将再次询问您(y/n)。这一切都很好,但当程序结束时,do/while循环似乎重新开始,它会询问您是否要“播放(y/n)”。 这方面的任何帮助都将是惊人的。为我愚蠢的自己道歉。我是新的编码,并认为这将是一个有趣的项目。 代码: import java.util

我正在尝试为一个项目制作skyrim的一部分,但似乎无法修复此do/while循环。我觉得我一直盯着这个问题看,却没有注意到它。 问题:我运行程序,它到达标题,它询问您是否要播放(y/n),它检查输入的键是否为“y”或“n”,如果不是,程序将再次询问您(y/n)。这一切都很好,但当程序结束时,do/while循环似乎重新开始,它会询问您是否要“播放(y/n)”。 这方面的任何帮助都将是惊人的。为我愚蠢的自己道歉。我是新的编码,并认为这将是一个有趣的项目。 代码:

import java.util.*;
公共级skyrim{
公共静态void简介(){
扫描仪输入=新扫描仪(System.in);
System.out.println(“简介…”);
System.out.println(“Continue…(x)”;
字符串B=input.next();
如果(B.以“x”开头){
对于(int b=0;b<50;b++){
System.out.println();
}         
}
System.out.println(“游戏…);
System.out.println(“Continue…(x)”;
字符串C=input.next();
如果(C.startsWith(“x”)){
对于(int c=0;c<50;c++){
System.out.println();
}         
}
System.out.println(“那绝对不是Skyrim…”);
System.out.println(“Continue…(x)”;
字符串D=input.next();
如果(D.以“x”开头){
对于(int d=0;d<50;d++){
System.out.println();
}         
}
System.out.println(“但实际上完全是……”);
System.out.println(“Continue…(x)”;
字符串E=input.next();
如果(例如,以“x”开头){
对于(int e=0;e<50;e++){
System.out.println();
}         
}
skyrimlogo();
System.out.println(“天空边缘:金爪之旅”);
//System.out.println(“*boom boom*”);
System.out.println(“贝塞斯达,请不要起诉我。”);
字符串next=“”;
做{
系统输出打印项次(“播放(y/n)”;
next=input.next();
if(next.startsWith(“y”)){
唤醒(输入);
}
if(next.startsWith(“n”)){
System.out.println(“退出游戏…”);
系统出口(0);
}
}
而(!next.startsWith(“y”)| |!next.startsWith(“n”);
}
公共静态无效skyrimlogo(){
System.out.println(“/\\/\\”);
System.out.println(“/()\ \”);
System.out.println(“//\”)(/\”);
System.out.println(“/(\\\”);
System.out.println(“/;\ \ \ \ \/)\ \ \ \”;
System.out.println(“/(,-。(\\\”);
System.out.println(“//)\\”;
System.out.println(“/,-”,“\\\”);
System.out.println(“/(\\(/)\\\”);
System.out.println(“/”。\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu;
System.out.println(“\\/”);
System.out.println(“\\.-,-./”);
System.out.println(“\\/\/\\(\\/\\/”);
System.out.println(“\\\)/”;
System.out.println(“\\\)/,”/”;
System.out.println(“\\\/\/”);
System.out.println(“\\\\\\;/”);
System.out.println(“\\)/”;
System.out.println(“\\\\;/(/”);
System.out.println(“\\)/”;
System.out.println(“///|”);
System.out.println(“\\\\\\/)”;
System.out.println(“\\/”);
System.out.println(“\\\\/”);
}
公共静态无效唤醒(扫描仪输入){
println(“你在一个寒冷的早晨醒来,坐在一辆马车后面,马车由一对马拉着。”);
//货车();
System.out.println(“Continue…(x)”;
字符串G=input.next();
如果(G.startsWith(“x”)){
对于(int g=0;g<7;g++){
System.out.println();
}         
}
System.out.println(“拉尔夫:嘿,你在那儿…”);
System.out.println(“你终于醒了,你想越境,对吧?”);
println(“和我们一样,直接闯入了帝国的伏击,还有那边的小偷。”);
System.out.println(“Continue…(x)”;
字符串H=input.next();
如果(H.startsWith(“x”)){
对于(int h=0;h<7;h++){
System.out.println();
}         
}
系统。输出。打印(“洛基:该死的风暴斗篷。在你出现之前,天空之林很好。帝国很好,很懒……”);
println(“如果他们没有找你,我可能会偷了那匹马,跑到哈默费尔的半路上。”);
系统。输出。打印(“你在那里。你和我——我们不应该在这里。这是帝国想要的风暴衣。”);
System.out.println(“Continue…(x)”;
字符串I=input.next();
如果(I.startsWith(“x”)){
对于(int i=0;i<7;i++){
System.out.println();
}         
}
“拉尔夫:我们现在都是兄弟姐妹了,小偷。”;
System.out.println(“Continue…(x)”;
字符串J=input.next();
如果(J.startsWith(“x”)){
对于(int j=0;j<7;j++){
System.out.println();
}         
} 
println(“你注意到一个男人把车开到你的左边,他穿着帝国盔甲。”);
println(“他注意到你盯着他,听到拉尔夫和洛基说话。”);
System.out.println(“闭嘴!”他说);
//山脉();
//WagonWissow();
System.out.println(“序号
import java.util.*;

public class skyrim {

   public static void intro() {
      Scanner input = new Scanner(System.in);
System.out.println("The intro...");
      System.out.println("Continue... (x)");
      String B = input.next();
      if (B.startsWith("x"))   {
         for (int b = 0; b < 50; b++)  {
            System.out.println();
         }         
      }
      System.out.println("To the game...");
      System.out.println("Continue... (x)");
      String C = input.next();
      if (C.startsWith("x"))   {
         for (int c = 0; c < 50; c++)  {
            System.out.println();
         }         
      }
      System.out.println("That is definitely not Skyrim...");
      System.out.println("Continue... (x)");
      String D = input.next();
      if (D.startsWith("x"))   {
         for (int d = 0; d < 50; d++)  {
            System.out.println();
         }         
      }
      System.out.println("But actually totally is....");
      System.out.println("Continue... (x)");
      String E = input.next();
      if (E.startsWith("x"))   {
         for (int e = 0; e < 50; e++)  {
            System.out.println();
         }         
      }
      skyrimlogo();
      System.out.println("SKYRIM: The Quest of The Golden Claw");
      //System.out.println("*boom boomboom BOOM*");  
      System.out.println("Bethesda please don't sue me."); 
      String next = "";             
      do {
      System.out.println("Play (y/n)");
      next = input.next();
      if (next.startsWith("y"))   {
         awake(input);
      }
      if (next.startsWith("n"))   {
         System.out.println("Exiting Game...");
         System.exit(0);
      }
      }
      while (!next.startsWith("y") || !next.startsWith("n"));
      }


   public static void skyrimlogo()  {
         System.out.println("         /\\       /\\");
         System.out.println("        / (       ) \\");
         System.out.println("       / /\\)     (/\\ \\");
         System.out.println("      / /   (\\      \\ \\");
         System.out.println("     / /    ; \\_/)   \\ \\");       
         System.out.println("    / /    (,-. (     \\ \\");
         System.out.println("   / /         ) )     \\ \\");
         System.out.println("  / /       ,-','       \\ \\");         
         System.out.println(" / /     (\\(  ( /)       \\ \\");         
         System.out.println("/  '._____)\\)  \\/(______,'  \\");         
         System.out.println("\\                           /");
         System.out.println(" \\     .-.         ,-.     /");
         System.out.println("  \\   /   \\/\\   (\\/   \\   / ");
         System.out.println("   \\  \\      \\   )    /  /  ");
         System.out.println("    \\  \\      ) /   ,'  /  ");
         System.out.println("     \\  \\    / /   |   /");
         System.out.println("      \\  \\   \\ \\   |  /");
         System.out.println("       \\  )   ) )  | /");
         System.out.println("        \\ |  / /   (/");
         System.out.println("         \\) / /    ");
         System.out.println("           / /  /|");
         System.out.println("           \\ \\_/ )");
         System.out.println("            \\   / ");
         System.out.println("             \\_/ ");

   }



   public static void awake(Scanner input) {
      System.out.println("You awake to a cold morning on the back of a cart pulled by a pair of horses.");
      //wagon();
      System.out.println("Continue... (x)");
      String G = input.next();
      if (G.startsWith("x"))   {
         for (int g = 0; g < 7; g++)  {
            System.out.println();
         }         
      }
      System.out.println("RALOF: Hey, you there...");
      System.out.println("You're finally awake. You were trying to cross the border, right?");
      System.out.println("Walked right into that imperial ambush, same as us, and the thief over there.");
      System.out.println("Continue... (x)");
      String H = input.next();
      if (H.startsWith("x"))   {
         for (int h = 0; h < 7; h++)  {
            System.out.println();
         }         
      }
      System.out.println("LOKIR: Damn you Stormcloaks. Skyrim was fine until you came along. Empire was nice and lazy...");
      System.out.println("If they hadnt been looking for you, I could've stolen that horse and been halfway to Hammerfell.");
      System.out.println("You there. You and me -- we shouldnt be here. It's these Stormcloaks the Empire wants.");
      System.out.println("Continue... (x)");
      String I = input.next();
      if (I.startsWith("x"))   {
         for (int i = 0; i < 7; i++)  {
            System.out.println();
         }         
      }
      System.out.println("RALOF: We're all brothers and sisters in binds now, thief.");
      System.out.println("Continue... (x)");
      String J = input.next();
      if (J.startsWith("x"))   {
         for (int j = 0; j < 7; j++)  {
            System.out.println();
         }         
      } 
      System.out.println("You notice the man driving the cart to your left and that he is dressed in imperial armour.");
      System.out.println("He notices you eyeing him and hears Ralof and Lokir talking.");
      System.out.println("'Shut up back there!' he says");

      //mountains();
      //wagonWithSnow();

      System.out.println("Snow continues to fall as the cart you have awoken on makes its way through the snowy mountain passes...");
      System.out.println("Continue... (Press Any Key)");
      String K = input.next();
      if (K.startsWith("x"))   {
         for (int k = 0; k < 7; k++)  {
            System.out.println();
         }         
      }
      System.out.println("[Lokir looks at the gagged man.]");
      System.out.println("LOKIR: And what's wrong with him?");
      System.out.println("Continue... (x)");
      String L = input.next();
      if (L.startsWith("x"))   {
         for (int l = 0; l < 7; l++)  {
            System.out.println();
         }         
      }
      System.out.println("RALOF: Watch your tongue! You're speaking to Ulfric Stormcloak, the true High King.");
      System.out.println("LOKIR: Ulfric? The Jarl of Windhelm? You're the leader of the rebellion. But if they captured you..."); 
      System.out.println("Oh gods, where are they taking us?");
      System.out.println("RALOF: I don't know where we're going, but Sovngarde awaits.");
      System.out.println("LOKIR: No, this can't be happening. This isn't happening.");
      System.out.println("Continue... (x)");      
      String M = input.next();
      if (M.startsWith("x"))   {
         for (int m = 0; m < 7; m++)  {
            System.out.println();
         }         
      }
      System.out.println("RALOF: Hey, what village are you from, horse thief?");
      System.out.println("LOKIR: Why do you care?");
      System.out.println("RALOF: A Nord's last thoughts should be of home.");
      System.out.println("LOKIR: Rorikstead. I'm...I'm from Rorikstead.");
      System.out.println("Continue... (x)");      
      String N = input.next();
      if (N.startsWith("x"))   {
         for (int n = 0; n < 7; n++)  {
            System.out.println();
         }         
      }
      System.out.println("As the cart makes its way through the snowy mountain passes, they arrive at the gates of Helgan.\n");
      //HelganGate();
      System.out.println("Continue... (x)");      
      String R = input.next();
      if (R.startsWith("x"))   {
         for (int r = 0; r < 7; r++)  {
            System.out.println();
         }         
      }     
      System.out.println("A soldier calls out to the lead wagon,");
      System.out.println("Imperial Soldier: General Tullius, sir! The headsman is waiting!");
      System.out.println("General Tullius: Good. Let's get this over with.");
      System.out.println("Continue... (x)");
      String O = input.next();
      if (O.startsWith("x"))   {
         for (int o = 0; o < 7; o++)  {
            System.out.println();
         }         
      }
      System.out.println("LOKIR: Shor, Mara, Dibella, Kynareth, Akatosh. Divines, please help me!");
      System.out.println("RALOF: Look at him, General Tullius the Military Governor. And it looks like the"); 
      System.out.println("Thalmor are with him. Damn elves. I bet they had something to do with this.");
      System.out.println("RALOF: This is Helgen. I used to be sweet on a girl from here. Wonder if Vilod");
      System.out.println("is still making that mead with juniper berries mixed in. Funny...when I");
      System.out.println("was a boy, Imperial walls and towers used to make me feel so safe.");
      System.out.println("Continue... (x)");
      String P = input.next();
      if (P.startsWith("x"))   {
         for (int p = 0; p < 7; p++)  {
            System.out.println();
         }         
      }
      System.out.println("[A man and son watch the prisoners pull into town.]");
      System.out.println("HAMING (little boy): Who are they, daddy? Where are they going?");
      System.out.println("TOROLF (father): You need to go inside, little cub.");
      System.out.println("HAMING (little boy): Why? I want to watch the soldiers.");
      System.out.println("TOROLF (father): Inside the house. Now.");
      System.out.println("Continue... (x)");
      String Q = input.next();
      if (Q.startsWith("x"))   {
         for (int q = 0; q < 7; q++)  {
            System.out.println();
         }         
      }
      System.out.println("[The wagon stops near the chopping block.]");
      System.out.println("IMPERIAL SOLDIER: \"Whoa...WHOA...whoa\" he says to the horses pulling the carriage");
      System.out.println("LOKIR: Why are they stopping?");
      System.out.println("RALOF: Why do you think? End of the line. Let's go. Shouldn't keep the gods waiting for us.");
      System.out.println("LOKIR: No! Wait! We're not rebels!");
      System.out.println("RALOF: Face your death with some courage, thief.");
      System.out.println("Continue... (x)");
      String V = input.next();
      if (V.startsWith("x"))   {
         for (int v = 0; v < 7; v++)  {
            System.out.println();
         }         
      }      
      System.out.println("[Under the Imperials' watchful eye, the prisoners start jumping out.]");
      System.out.println("LOKIR: You've got to tell them! We weren't with you! This is a mistake!");
      System.out.println("IMPERIAL CAPTAIN: Step toward the block when we call your name. One at a time!");
      System.out.println("RALOF: Empire loves their damn lists.");
      System.out.println("Continue... (x)");
      String S = input.next();
      if (S.startsWith("x"))   {
         for (int s = 0; s < 7; s++)  {
            System.out.println();
         }         
      } 
      System.out.println("HADVAR: Ulfric Stormcloak. Jarl of Windhelm.");
      System.out.println("RALOF: It has been an honor, Jarl Ulfric!");
      System.out.println("Continue... (x)");
      String T = input.next();
      if (T.startsWith("x"))   {
         for (int t = 0; t < 7; t++)  {
            System.out.println();
         }         
      } 
      System.out.println("HADVAR: Ralof of Riverwood. Lokir of Rorikstead.");
      System.out.println("LOKIR: No, I'm not a rebel! You can't do this!");
      System.out.println("[He makes a break for it.]");
      System.out.println("IMPERIAL CAPTAIN: Halt!");
      System.out.println("LOKIR: You're not going to kill me!");
      System.out.println("IMPERIAL CAPTAIN: Archers!");
      System.out.println("[Lokir is downed with one bowshot.]");
      //archer();
      System.out.println("IMPERIAL CAPTAIN: Anyone else feel like running?");
      System.out.println("[One of the guards looks back over to you with a sad expression on his face.]");
      System.out.println("HADVAR: Wait, you there. Step forward. Who are you?");

   }

   }
do {

   next = input.next();

while (!next.startsWith("y") || !next.startsWith("n"));
not(x) or not(y) = not(x and y)
not(next.startsWith("y")) or not(next.startsWith("n")) 
not(next.startsWith("y") and next.startsWith("n"))
do {

   next = input.next();

while (!next.startsWith("y") && !next.startsWith("n"));
!next.startsWith("y") || !next.startsWith("n")
!true || !false
false || true
true
!next.startsWith("y") && !next.startsWith("n")