一个小程序,望大虾指正
一个涉及文件操作读取,以及令牌环的小程序,一直不明白为什么出错,我可是按书上写的阿
从W.TXT中读取数据,然后操作,输出结果,我现在不明白的是为什么在StringTokenizer处报错,说
“StringTokenizer cannot be resolved to a type”,这是什么意思啊
import java.io.*;
import java.text.*;
public class First{
public static void main(String args[])throws IOException,FileNotFoundException{
int a,b,c,d,sum,product;
char str,ch;
StringTokenizer tokenizer;
BufferedReader inFile=new BufferedReader(new FileReader("c:\\w.txt"));
PrintWriter outFile=new PrintWriter(new FileWriter("C:\\q.txt"));
tokenizer=new StringTokenizer(inFile.readLine());
a=Integer.parseInt(tokenizer.nextTokenizer());
b=Integer.parseInt(tokenizer.nextTokenizer());
str=tokenizer.nextToken());
c=Integer.parseInt(tokenizer.nextTokenizer());
d=Integer.parseInt(tokenizer.nextTokenizer());
sum=a+b;
product=c*d;
ch=(char)(str+1);
outFile.print("sum");
outFile.close();
}
}
问题点数:10、回复次数:5Top
1 楼aaa2003gf(珍惜 (MSN:aaa2003gf@hotmail.com))回复于 2006-03-03 20:05:09 得分 10
java.util
Class StringTokenizer
你没引入
前面加import java.util.*;
str=tokenizer.nextToken()); 把后面的括号去掉。Top
2 楼zx2002027(http://www.netyi.net/in.asp?id=zx2002027)回复于 2006-03-04 12:51:33 得分 0
楼上正解Top
3 楼bossycrab(螃蟹)回复于 2006-03-04 15:00:28 得分 0
受益Top
4 楼f_acme(沧海一声笑)回复于 2006-03-04 15:15:02 得分 0
StringTokenizer cannot be resolved to a type
就是说类型不能识别,找不到类。Top
5 楼wang8118(普罗旺斯的天空)回复于 2006-03-04 18:09:29 得分 0
改了,可是另一个错误又来了
import java.io.*;
import java.util.*;
public class First{
public static void main(String args[])throws IOException,FileNotFoundException{
int a,b,c,d,sum,product,num;
char ch,str;
StringTokenizer tokenizer;
BufferedReader inFile=new BufferedReader(new FileReader("c:\\w.txt"));
PrintWriter outFile=new PrintWriter(new FileWriter("C:\\q.txt"));
tokenizer=new StringTokenizer(inFile.readLine());
a=Integer.parseInt(tokenizer.nextToken());
b=Integer.parseInt(tokenizer.nextToken());
str=tokenizer.nextToken();
c=Integer.parseInt(tokenizer.nextToken());
d=Integer.parseInt(tokenizer.nextToken());
sum=a+b;
product=c*d;
ch=(char)(str+1);
outFile.print("the sum of "+a+" and "+b+"="+sum +"\n"
+"the character that comes after "+str+"in the Unicode set is"+ch+"\n"
+"the product of "+c+" and "+d+"="+product);
outFile.close();
}
}
现在又有了新的问题,我的w.txt中内容是:
12 34
A
67 589
我的问题是怎么样把A的下一个字母算出来,即B,由于str=tokenizer.nextToken();报错,是因为
字符串不能赋给一个字符,可我又想不到别的方法,转成ASC码也不行,大家帮我啊,该怎么改啊?
谢谢了Top




