注册 登录
编程论坛 JAVA论坛

用Java StringBuffer方法 怎么解

sally02468 发布于 2015-11-11 22:55, 449 次点击
题目:请编写一个程序,读取“Enter a line of text.No punctuation(标点) please”作为输入,然后显示文本,把该行的第一个单词移到行尾,显示新的文本。
要求:假定第一个单词之前没有空格,第一个单词的末尾使用一个空格指示,新的第一个单词必须以大写字母开头。
 
这是没用StringBuffer写的,是错的
有StringBuffer怎么写呢

import java.util.Scanner;
public class Test {

    public static void main(String[] args) {
        System.out.println("Enter a line of text.No punctuation(标点) please.");
        Scanner reader=new Scanner(System.in);
        String [] str=new String[100];
        for(int i=0;i<STR.LENGTH;I++){
       str[i]=reader.next();
        String str[1] =str.nextLine();
        str=str[1].split(" ");
        }
        str[1]=str[1].replaceFirst(str[1].substring(0,1)
                ,str[1].substring(0,1).toUpperCase());
        System.out.println("I have rephrased that line to read:");
        for(int i=1;i<STR.LENGTH;I++)
            System.out.print(str[i]+" ");
        System.out.println(str[0]);
        
        }
   
    }
0 回复
1