我想打印用户输入的所有字母,但问题是,我的程序只打印用户输入的最后一个值,并且只有最后一个值记录在Ascii.txt
. 它应该看起来像这样
例如:用户输入 A,B,c,C
我也想删除逗号,但我不能:(
“Ascii.txt”中的输出应该是:
A = 65
B = 66
c = 99
C = 67
请不要笑我,因为我还是个学生和编程新手,非常感谢
import java.io.*;
public class NewClass2{
public static void main(String args[]) throws IOException{
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please Enter letters separated by comma: ");
String str = buff.readLine();
for ( int i = 0; i < str.length(); ++i )
{
char c = str.charAt(i);
int j = (int) c;
System.out.println(c +" = " + j);
{
try
{
FileWriter fstream = new FileWriter("Ascii.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write(c+" = "+j);
out.close();
}catch (Exception e){
}
}
}
}
}