import java.util.*;
public class SubString_1 {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.println("请要截取的输入字符串:");
String str=in.next();
System.out.println("请输入要截取的字节的首尾上标");
int fromIndex=in.nextInt();
System.out.println("请输入要截取的字节的首尾下标");
int toIndex=in.nextInt();
SubString_1 sp=new SubString_1();
System.out.println(sp.cutString(str, fromIndex, toIndex));
}
public String cutString(String str,int fromIndex,int toIndex) {
String str2="";
String str3="";
for(int i=fromIndex;i<=toIndex;) {
str2=str2+str.charAt(i);
int k=str2.getBytes().length;
str3=str2+str.charAt(i+1);
int s=str3.getBytes().length;
if(fromIndex+k-1
i++;//目前状态下和后一个状态都要考虑
}else {
break;
}
}
return str2;
}
}
发表于 2019-12-28 22:43:58
回复(0)