当前位置: 技术问答>java相关
帮帮忙看看程序错在那里!
来源: 互联网 发布时间:2015-07-21
本文导语: import java.awt.*; import java.io.*; import java.util.*; import java.lang.*; import java.lang.String; public class alysor { public static void main(String args[]) { String str=null; System.out.println("Enter a infomation by the form...
import java.awt.*;
import java.io.*;
import java.util.*;
import java.lang.*;
import java.lang.String;
public class alysor
{
public static void main(String args[])
{
String str=null;
System.out.println("Enter a infomation by the form.");
System.out.print(">: ");
str=str+"LOGIN"+" ";
str=str+"CMPP/1.2";
str=str+"nr";
str=str+"CSeq:1";
str=str+"nr";
str=str+"From:10.12.12.1";
str=str+"nr";
str=str+"To:123.12.12.1";
str=str+"nr";
str=str+"Timerstamp:2002-07-22T08:47:12Z";
find f=new find();
f.findString(str);
}
}
class find
{
public void findString (String str)
{
String strtext=null;
StringTokenizer t_substr;
StringTokenizer t_str=new StringTokenizer(str,"nr");
while (t_str.hasMoreTokens())
{
strtext=t_str.nextToken();
strL=strtext.length();
t_substr=new StringTokenizer(strtext," ");
while(t_substr.hasMoreTokens())
{
System.out.println(t_substr.nextToken());
}
}
if(!t_substr.hasMoreTokens())
{
if(strtext.indexof("From:")!=-1)
System.out.println(strtext.substring(5,strL));
else if(strtext.indexof("To:")!=-1)
System.out.println(strtext.substring(3,strL));
else if(strtext.indexof("Timerstamp:")!=-1)
System.out.println(strtext.substring(11,strL));
else if(strtext.indexof("Authenticate")!=-1)
System.out.println(strtext.substring(21,strL));
}
//if end
}
//viaria difinition
int strL=0;
final private String FROM="From:";
final private String TO="To:";
final private String TIMERSTAMP="Timerstamp:";
final private String AUTHENTICATE="Authenticate";
}
上面的程序编译时提示错误 connot resolve symble indexof
import java.io.*;
import java.util.*;
import java.lang.*;
import java.lang.String;
public class alysor
{
public static void main(String args[])
{
String str=null;
System.out.println("Enter a infomation by the form.");
System.out.print(">: ");
str=str+"LOGIN"+" ";
str=str+"CMPP/1.2";
str=str+"nr";
str=str+"CSeq:1";
str=str+"nr";
str=str+"From:10.12.12.1";
str=str+"nr";
str=str+"To:123.12.12.1";
str=str+"nr";
str=str+"Timerstamp:2002-07-22T08:47:12Z";
find f=new find();
f.findString(str);
}
}
class find
{
public void findString (String str)
{
String strtext=null;
StringTokenizer t_substr;
StringTokenizer t_str=new StringTokenizer(str,"nr");
while (t_str.hasMoreTokens())
{
strtext=t_str.nextToken();
strL=strtext.length();
t_substr=new StringTokenizer(strtext," ");
while(t_substr.hasMoreTokens())
{
System.out.println(t_substr.nextToken());
}
}
if(!t_substr.hasMoreTokens())
{
if(strtext.indexof("From:")!=-1)
System.out.println(strtext.substring(5,strL));
else if(strtext.indexof("To:")!=-1)
System.out.println(strtext.substring(3,strL));
else if(strtext.indexof("Timerstamp:")!=-1)
System.out.println(strtext.substring(11,strL));
else if(strtext.indexof("Authenticate")!=-1)
System.out.println(strtext.substring(21,strL));
}
//if end
}
//viaria difinition
int strL=0;
final private String FROM="From:";
final private String TO="To:";
final private String TIMERSTAMP="Timerstamp:";
final private String AUTHENTICATE="Authenticate";
}
上面的程序编译时提示错误 connot resolve symble indexof
|
indexof()???
indexOf()
大小写!
indexOf()
大小写!
|
你的程序還是有錯.在定義t_substr之后﹐在while語句里你初始化了﹐但后面的if(!t_substr.hasMoreTokens())中的t_substr沒有初始化.