看板 java 關於我們 聯絡資訊
剛開始學java 很多都還一支半解 想請教各位大大 ====================================================================== import java.util.*; import java.util.Scanner; public class Prac2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); do { String guess; int wL=0; char hidden='r'; char gchar; System.out.println("enter your word, stop to end."); guess = sc.nextLine(); wL = guess.length(); while(guess != 'stop') { for(int i=0;i<wL;i++) { gchar=guess.charAt(i); if(gchar = hidden) { System.out.println("Your guess does not contain the secret letter"); System.out.println("enter next word, stop to end."); guess = sc.nextLine() } else { System.out.println("Your guess contains the secret letter"); System.out.println("enter next word, stop to end."); guess = sc.nextLin() } } } } } } ============================================================== 這個程式有什麼問題 要怎麼修改呢? 我試了好久> < 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 121.223.160.59
zhengdavy:查看看字串比較跟判斷式的運算子 09/13 16:05
zhengdavy:for loop裡有問題, 你試試看自己一行一行走一遍 09/13 16:13
zhengdavy:看不懂你是在寫do while loop還是while loop 09/13 16:15
ayumi001:if(gchar = hidden) 編譯錯誤 要"兩"個等號才會是boolean 09/13 16:36
MiaShopgirl:看起來是猜字遊戲.. 請參考 http://goo.gl/Z5wl0 09/13 17:05
darkk6:關鍵字,查一下:字串、字元常數、字串的比較、比較運算子 09/13 17:24
hoby:謝謝大家 我會再研究看看^^ 09/13 17:42
waterleader:基本語法就有很多問題。 09/20 13:13