9.字符串右移n位,例如 "hello world" 右移两位 后ldhello wor
要求写一个方法实现此功能,方法的格式是
String moveToRight(String str,int position)
str:需要移动的字符串
p:右移的位数
String moveToRight(String str,int position)
{
return str.subString(str.length - position - 1) + str.subString(0, position);
}
static String moveToRight(String str,int position)
{
return str.substring(str.length()-position,str.length()) + str.substring(0, str.length()-position);
}
public class MyClass {
static String moveToRight(String str,int position)
{
return str.substring(str.length() - position - 2) + str.substring(0, position);
}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
System.out.println(moveToRight("123456", 2));
}
}
345612
测试通过