java - 将第一个单词移动到 Java 中的最后一个位置

标签 java

如何让 Jave is the language 成为 Is the language 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() 的底部,把这个:

return rephrase;

关于java - 将第一个单词移动到 Java 中的最后一个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35837245/

相关文章:

java - Android 应用程序未在其他设备上运行

java - 将小程序添加到网站

java - 如何检测运算符的空格

java - 在 Java 中使用策略模式的电子邮件程序

java - 合并 pdf :s with pdfBox creates a unnecessary large file

Java 在单元格数量减半后开始读取 null

java - 是否可以有一个包含对象构造函数的枚举?

Java MongoDB 在多个字段中搜索值

java - 如何在 Java 或 Clojure 中用正则表达式替换字符串

java - 我的返回值始终等于 0