Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JAVA代码中循环的建议_Java_Loops_Nested Loops - Fatal编程技术网

JAVA代码中循环的建议

JAVA代码中循环的建议,java,loops,nested-loops,Java,Loops,Nested Loops,我有这个程序,我目前正在工作,需要帮助添加一个循环到它。这是一个猜字益智游戏,每个玩家都应该能够猜出尽可能多的字母,直到猜错一个字母为止。然后它将移动到下一个玩家。 现在,它只要求每个玩家一次一封信,然后它继续下一个玩家,依此类推,然后程序结束。 任何建议都将不胜感激。 以下是我目前的代码: public class PuzzleGuess{ public static void main(String []args){ System.out.println("Welcome!!"

我有这个程序,我目前正在工作,需要帮助添加一个循环到它。这是一个猜字益智游戏,每个玩家都应该能够猜出尽可能多的字母,直到猜错一个字母为止。然后它将移动到下一个玩家。 现在,它只要求每个玩家一次一封信,然后它继续下一个玩家,依此类推,然后程序结束。 任何建议都将不胜感激。 以下是我目前的代码:

public class PuzzleGuess{

 public static void main(String []args){

    System.out.println("Welcome!!");

    System.out.println("Availble letters:");

    String[] letter = new String[]{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};

    for(int a=0;a<26;a++)

      System.out.print(letter[a]);

      System.out.println("");

    System.out.println("_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _");

    String[] Guess = new String[]{"S", "W", "E", "E", "T", "H", "O", "M", "E", "A", "L", "A", "B", "A", "M", "A"};

    System.out.println("No of players:"+3);

   int ch,flag=0,r;

    String s;

    Scanner scan = new Scanner(System.in);

    for(int i=1;i<=3;i++)

    {

        System.out.println("players:"+i);

        System.out.println("Select any one 1) spin wheel 2) Guess");

        ch=scan.nextInt();

        if(ch==1)

        {

            Random t = new Random();

            r=t.nextInt(10)+1;

            if(r==1)

            {

              System.out.println("you are landed on $100.");

            }

              else if(r==2)

              {

              System.out.println("you are landed on $300.");

              }

              else if(r==3)

              {

              System.out.println("you are landed on $500.");

            }

              else if(r==4)

              {

              System.out.println("you are landed on $700.");

              }

              else if(r==5)

              {

              System.out.println("you are landed on $900.");

              }

              else if(r==6)

              {

              System.out.println("you are landed on $2000.");

              }

              else if(r==7)

              {

              System.out.println("you are landed on $3000.");

              }

             else if(r==8)

              {

              System.out.println("you are landed on $5000.");

              }

              else if(r==9)

              {

              System.out.println("you are landed on $-1000.");

              }

              else

              {

              System.out.println("you are landed on $0.");

              }

        }

        else if(ch==2)

      {

            System.out.println("Select your letter from available letters ");

            s = scan.next();

            for(int g=0;g<16;g++)

            {



                 if(s.equals(Guess[g]))

                 {

                     flag=1;



                 }

            }

            if(flag==1)

            {

                System.out.println("correct");

                for(int a=0;a<26;a++)

              {

                    if(s.equals(letter[a]))

                    {

                        letter[a]=null;

                    }

                }

                for(int a=0;a<26;a++)

                 System.out.print(letter[a]);

                 System.out.println("");



            }

            else

            {

                System.out.println("Incorrect");

首先创建一些对象和方法,在其中移动代码。
您应该拆分代码以简化对代码的理解。

请不要在发布代码时有100行空行。这是不必要的阅读困难。任何建议都是不适合StackOverflow主题的问题,我们将不胜感激。你应该考虑查看CooDeVIEW栈交换,看看你的问题是否适合他们站点的主题,因为这个问题可能是合适的。