如何数字分离?

lijianbin9 2010-03-22 03:46:59
比如输入 8802135986351
输出结果为:(就是把 生日和后面的代码 分 两行输出)
880213
5986351
...全文
134 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
24K純帥 2010-03-22
  • 打赏
  • 举报
回复
substring反正是固定的
keeya0416 2010-03-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 lijianbin9 的回复:]
String s2=s.subString(6,s.length());
这里的s Substring 分别什么意思啊?/
[/Quote]
就是截取子字符串,从第一个参数(包括)开始 到 第二个参数(不包括)结束。
auvfk7yi 2010-03-22
  • 打赏
  • 举报
回复
用substring这个方法截取就好了。
wensefu 2010-03-22
  • 打赏
  • 举报
回复
用eclipse直接查看jdoc:
substring
public String substring(int beginIndex,
int endIndex)
Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.
Examples:

"hamburger".substring(4, 8) returns "urge"
"smiles".substring(1, 5) returns "mile"


Parameters:
beginIndex - the beginning index, inclusive.
endIndex - the ending index, exclusive.
Returns:
the specified substring.
Throws:
IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex.
quansheng3510 2010-03-22
  • 打赏
  • 举报
回复
分割字符串,你自己去查api文档的String方法,
guo624587253 2010-03-22
  • 打赏
  • 举报
回复
String str = "8802135986351";
if (str.length() >= 6) {
System.out.println(str.substring(0, 6));
System.out.println(str.substring(6,str.length()));
}
lijianbin9 2010-03-22
  • 打赏
  • 举报
回复
String s2=s.subString(6,s.length());
这里的s Substring 分别什么意思啊?/
quansheng3510 2010-03-22
  • 打赏
  • 举报
回复
生日的年加月日共6位,所以你
String s="8802135986351";
String s1=s.subString(0,6);
String s2=s.subString(6,s.length());
system.out.println(s1);
system.out.println(s2);
lijianbin9 2010-03-22
  • 打赏
  • 举报
回复
那位给 写一下。。。比较急。。 感激ing

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧