Re: [問題] 檢查保留字的程式
歹勢啦,為了方便我把兩個都寫在同一個記事本裡~~~
※ 引述《slayer.bbs@bbs.wretch.cc (foolish)》之銘言:
: 這是什麼鬼, 為什麼有二個同樣名字的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
: > 所以很好奇是哪邊的語法寫錯了…
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.162.93.38
討論串 (同標題文章)