作者nothao (hao)
看板java
标题[问题] 检查保留字的程式
时间Wed Apr 5 14:54:43 2006
因为不知道指令是哪一个,所以我就用一个类别来做为检查的方式
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