Re: [問題] 檢查保留字的程式

看板java作者時間18年前 (2006/04/05 15:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/17 (看更多)
這是什麼鬼, 為什麼有二個同樣名字的class 這不是java啊... ※ 引述《nothao.bbs@ptt.cc (hao)》之銘言: > 因為不知道指令是哪一個,所以我就用一個類別來做為檢查的方式 > import javax.swing.JOptionPane; > public class test{ > public static void main(String[] args){ > String box =JOptionPane.showInputDialog("請輸入字串");//box裝初始字串 > String box1;//box1裝檢察字串 > text t1 =new text(); > int num; > num = box.indexOf(' ');//檢查空白 > int num1 =0 ; > if(num != -1){ > while( num != -1){ > box1=box.substring(num1,num); > t1.text(box1); > num1=num + 1 ; > num = box.indexOf(num1,' '); > } > } > else{ > t1.text(box); > } > } > } > class text(){ > String[] array = {"abstract","do","implements","protected","throws", > "boolean","double","import","public","transient","break","else","instanceof", > "return","true","byte","extends","int","short","try","case","false","interface", > "static","void","catch","final","long","strictfp","volatile","char","finally", > "native","super","while","class","float","new","switch","const","for","null", > "synchronized","continue","goto","package","this"}; > public static text(String x){ > int j = 0; > while(j <= 53){ > if(x.equals(array[j]) > System.out.println("字串"+ x + "為保留字"); > else > j++; > } > System.out.print("沒有保留字"); > } > } > 卻出現錯誤訊息 > t1.text(box1); symbol:method text(java.lang.String) location:class text > 所以很好奇是哪邊的語法寫錯了… -- 夫兵者不祥之器物或惡之故有道者不處君子居則貴左用兵則貴右兵者不祥之器非君子 之器不得已而用之恬淡為上勝而不美而美之者是樂殺人夫樂殺人者則不可得志於天下 矣吉事尚左凶事尚右偏將軍居左上將軍居右言以喪禮處之殺人之眾以哀悲泣之戰勝以 喪禮處之道常無名樸雖小天下莫能臣侯王若能守之萬物將自賓天地相合以降甘露民莫 之令而自均始制有名名亦既有夫亦將知止知止可以 pc210-59-94-148.nutn.edu.tw
文章代碼(AID): #14Ct9r00 (java)
討論串 (同標題文章)
文章代碼(AID): #14Ct9r00 (java)