Topic: 关于Java读入数据的问题。

  Print this page

1.关于Java读入数据的问题。 Copy to clipboard
Posted by: DarKnight
Posted on: 2003-11-18 17:14

请问在java如何实现把用户输入数据12*30#,写入 int hour = 12, int minute = 30(就是把String 12*30#过滤掉*和#,并把小时和分钟分开读入,小时可以为单数9或双数11)?谢谢。

2.Re:关于Java读入数据的问题。 [Re: DarKnight] Copy to clipboard
Posted by: wlai
Posted on: 2003-11-18 23:18

字符串处理常用 StringTokenizer 分解, 但你有 * 及 # 会较烦琐.
如果格式是 nn:nn:nn 会较简单.

3.Re:关于Java读入数据的问题。 [Re: DarKnight] Copy to clipboard
Posted by: sc33
Posted on: 2003-11-19 10:31

String inStr = "12*30#";
int hour = -1;
int minute = -1;

hour = Integer.parseInt(inStr.substring(0,inStr.indexOf("*")));
minute = Integer.parseInt(inStr.substring(inStr.indexOf("*")+1,inStr.indexOf("#")));

4.Re:关于Java读入数据的问题。 [Re: DarKnight] Copy to clipboard
Posted by: DarKnight
Posted on: 2003-11-19 12:24

谢谢! Smile


   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