Re: [問題] 檢查保留字的程式
※ 引述《nothao (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
: 所以很好奇是哪邊的語法寫錯了…
簡單的說, 是你沒有提供預設建構子 (真奇怪為什麼你沒這個error)
而你的另一個建構子被當成method !? 是你訊息不完整嗎@"@
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 163.26.34.20
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 9 之 17 篇):