class Demo1234
{
public static void main(String[] args)
{
String s1 = " abc abc ";
String s2 = "abcdefgh";
String s = "";
String ss = "";
s = Converse(s2);
ss = Converse(s2,1,5);
sop(s);
}
public static void sop(Object obj)
{
System.out.println(obj);
}
public static String Converse(String str)
{
char[] chs = str.toCharArray();
char[] chs1 = new char[chs.length];
for (int i = 0,j = chs.length - 1; i < chs.length ;i++,j-- )
{
chs1[i] = chs[j];
}
String s = new String(chs1);
return s;
}
public static String Converse(String str, int start ,int end)
{
char[] chs = str.toCharArray();
char[] chs1 = new char[chs.length];
int len = 0;
for (int i = start,j = end; i < end ;i++,j-- )
{
chs1[len] = chs[j];
len++;
}
String s1 = new String(chs1);
String s2 = substring(0,start);
String s3 = substring(end-1,chs.length);
String s = s1+s2+s3;
return s;
}
}
编译错误,找不到原因 |
|