作者zanyking (遥远的旅人)
看板java
标题Re: [问题] 检查保留字的程式
时间Sun Apr 9 22:12:48 2006
※ 引述《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",
^^你底下的方法是static的,这里却不是static,你方法里头根本呼叫不到他。
: "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){
^^^^^^方法名称与class名称相同,而且没有回传型态。
即使是void,你还是宣告回传为void。
: 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
: 所以很好奇是哪边的语法写错了…
如果是C#的话,static建构子是没有引数(参数)且不可能为外部呼叫的。
那是CLR在 class Loading的时候由class loader去做的,你不能操纵它。
--
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.85.116.116
※ 编辑: zanyking 来自: 210.85.116.116 (04/10 01:27)