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

看板java作者 (hao)時間18年前 (2006/04/05 14:49), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/17 (看更多)
因為不知道指令是哪一個,所以我就用一個類別來做為檢查的方式 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 所以很好奇是哪邊的語法寫錯了… -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.162.93.38
文章代碼(AID): #14CsYHcE (java)
討論串 (同標題文章)
文章代碼(AID): #14CsYHcE (java)