[已解决][java]有个关於next line既bug唔识搞
时间:2013-12-22
来源:互联网
Angus : 9.31, 13.32, 10.70
Mandy : 12.18
Sandy : 14.35, 10.15
Arma : 9.86, 10.49
Golden : 12.35, 11.41
Amiee : 11.38
Athenae : 12.37
Issac : 8.96, 12.36
import java.io.IOException;
import java.util.Scanner;
public class RecordTest {
public static void main(String[] args) throws IOException {
FileReader reader = new FileReader ("d:/RaceRecord.txt");
Scanner scanner = new Scanner (reader);
scanner.useDelimiter(" : |, |\n");
String name = null;
Double key;
while (scanner.hasNext())
{
if (!scanner.hasNextDouble()) {
name = scanner.next();
System.out.println(name);
} else {
key = Double.parseDouble(scanner.next());
System.out.printf("%.02f %s\n", key, name);
}
}
}
}
15.33 Sugus
11.32 Sugus
11.97 Sugus
Angus
9.31 Angus
13.32 Angus
10.70 Angus
Mandy
12.18 Mandy
Sandy
14.35 Sandy
10.15 Sandy
Arma
9.86 Arma
10.49 Arma
Golden
12.35 Golden
11.41 Golden
Amiee
11.38 Amiee
Athenae
12.37 Athenae
Issac
8.96 Issac
12.36 Issac
15.33 Sugus
11.32 Sugus
11.97
Angus
9.31 Angus
13.32 Angus
10.70
Mandy
12.18
Sandy
14.35 Sandy
10.15
Arma
9.86 Arma
10.49
Golden
12.35 Golden
11.41
Amiee
11.38
Athenae
12.37
Issac
8.96 Issac
12.36 Issac
如果将所有row摆晒同一行就出到expected result
请指教衰左系边
大感谢
[ 本帖最后由 Qoo记 於 2013-11-28 12:54 AM 编辑 ]
作者: Qoo记 发布时间: 2013-12-22
作者: a8d7e8 发布时间: 2013-12-22
i don't quite understand what you mean
the standard form of the record is:
name : double1, double2, ..., doublen
name2...
my approach is divide data into [name] [double1] [double2] ...
for delimiter [ : ] [, ], they work
but for [\n] or [\\n], it doesn't work
hope to see more detail
thanks_____________________________________________
for reference:
input :
[ 本帖最后由 Qoo记 於 2013-11-28 12:42 AM 编辑 ]
作者: Qoo记 发布时间: 2013-12-22
notepad既nextline并非单纯既\n
而系\r\n
作者: Qoo记 发布时间: 2013-12-22
已解决
notepad既nextline并非单纯既\n
而系\r\n
作者: a8d7e8 发布时间: 2013-12-22
啱啱做咗个实验,原来 scanner.hasNextDouble() 系好严格,字串内唔容许空白字元(空格、\t、\r、等等),一有就传回假。
同 Double.parseDouble() 好唔同,内含空白字元系无问题。
因此,显示记录最后一个数值,其实系变数 name。
作者: fitcat07 发布时间: 2013-12-22
我错了.
我噚晚谂应该同视窗新行字元系 "\r\n" 有关,但就唔明白点解输出会唔见咗 name。
啱啱做咗个实验,原来 scanner.hasNextDouble() 系好严格,字串内唔容许空白字元(空格、\t、\r、等等), ...
作者: a8d7e8 发布时间: 2013-12-22
___________________
今次真系冇活用网上resource
系stackoverflow打算问个阵有关键字即prompt我去相关post
一睇就知问题
平白晒左几日
___________________
also thanks a8d7e8 ching for replying the topic
作者: Qoo记 发布时间: 2013-12-22
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28