-4
我有這個程序,我目前正在工作,需要幫助添加一個循環。它是一個猜字遊戲,每個玩家都應該能夠猜出儘可能多的字母,直到他們猜出錯誤的字母爲止。然後它會轉向下一個玩家。 現在它只要求每個玩家1次寫一封信,然後繼續下一個玩家等等,然後程序結束。 任何意見將不勝感激。 這是我的代碼到目前爲止:在我的JAVA代碼中的循環建議
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");
請不要將您的代碼與一百個空白行放在其中。這是不必要的閱讀困難。 – khelwood
_Any建議將不勝感激_是StackOverflow脫離主題的那種問題。您應該考慮查看CodeReview Stack Exchange以查看您的問題是否符合他們網站主題的要求,因爲此問題可能適合您。 – Lexi