Topic: 求助: 为啥没有预计输出到?

  Print this page

1.求助: 为啥没有预计输出到? Copy to clipboard
Posted by: aaarong
Posted on: 2007-03-24 09:56


import java.util.*;
import java.io.*;
public class ScannerTest
{ public static void main(String[] args)
{ Integer[] it=new Integer[]{1,2,3,4,5,6,7,8,9,10};
String[] str=new String[]{"aaarong","money","abcdefg","memoey",
"enery","mmmmm","mybole","enneil",
"esneg","ksajfl"};
try{
FileWriter f=new FileWriter("Test.txt");
for(int i=0;i<it.length;i++)
{ f.write(str[i]);
f.write("=");
f.write(it[i]);
f.write('\n');
}
f.close();
FileReader fin=new FileReader("Test.txt");
Scanner s=new Scanner(fin);
while(s.hasNext())
{ if(s.hasNextInt())
{ int K=s.nextInt();
System.out.println(K);
}
else
{ String M=s.next();
System.out.println(M);
}
}
fin.close();
}catch(Exception e)
{ System.out.println("Error");
}
}
}

而编译后输出是

2.Re:求助: 为啥没有预计输出到? [Re: aaarong] Copy to clipboard
Posted by: why
Posted on: 2007-03-24 19:13

f.write("" + it[i]);

3.Re:求助: 为啥没有预计输出到? [Re: aaarong] Copy to clipboard
Posted by: aaarong
Posted on: 2007-03-25 07:34

明白了 太感谢了!!!!

4.Re:求助: 为啥没有预计输出到? [Re: aaarong] Copy to clipboard
Posted by: aaarong
Posted on: 2007-03-25 07:52

是因为it[i]后面跟的是字符串所以必须加个连接符吗?

5.Re:求助: 为啥没有预计输出到? [Re: aaarong] Copy to clipboard
Posted by: why
Posted on: 2007-03-25 08:37

f.write(it[i]); //輸出it[i]值,讀入然後列印時則是與it[i]相對的char
f.write("" + it[i]); //輸出it[i]值的字串:it[i]=2, "" + it[i] =>"2"

6.Re:求助: 为啥没有预计输出到? [Re: aaarong] Copy to clipboard
Posted by: aaarong
Posted on: 2007-03-25 08:50

谢谢 已经能理解了 太感谢了


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923