我該如何讓Jave is the language
爲Is the language Java
這是我的代碼,但我認爲這裏有一些問題。將第一個單詞移到Java中的最後一個位置
public class Lab042{
public static final String testsentence = "Java is the language";
public static void main(String [] args) {
String rephrased = rephrase(testsentence);
System.out.println("The sentence:"+testsentence);
System.out.println("was rephrased to:"+rephrased);
}
public static String rephrase(String testsentence) {
int index = testsentence.indexOf (' ');
char c = testsentence.charAt(index+1);
String start = String.valueOf(c).toUpperCase();
start += testsentence.substring(index+2);
start += " ";
String end = testsentence.substring(0,index);
String rephrase = start + end;
}
}
你應該在'rephrase()'中使用'StringBuilder'。 – 2016-03-07 06:12:18
獅子座,如果這裏有正確的答案,請注意。 –