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码也不行,大家帮我啊,该怎么改啊?
谢谢了
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码也不行,大家帮我啊,该怎么改啊?
谢谢了
简单啊,这样改:str=tokenizer.nextToken().charAt(0);
str = temp.charAt(0);不就好了阿?