249
社区成员
发帖
与我相关
我的任务
分享
public class Test{
public static void main(String[] args) {
String str="101";
long position=pos(str);
System.out.println(str+"的位置是: 从"+position+"到"+(position+str.length()));
}
static long pos(String str){
long x=Long.parseLong(str),y=1;
long position=0;
for(int i=1;i<=str.length()-1;i++){
position+=y*9*i;
y*=10;
}
position+=(x-y)*str.length();
return position+1;
}
}