运用JAVA语言实现对一句话的移位,例如:输入“I like dancing”输出“like dancing I dancing I like”.
来源:学生作业帮助网 编辑:六六作业网 时间:2025/01/19 18:18:14
运用JAVA语言实现对一句话的移位,例如:输入“I like dancing”输出“like dancing I dancing I like”.
运用JAVA语言实现对一句话的移位,例如:输入“I like dancing”输出“like dancing I dancing I like”.
运用JAVA语言实现对一句话的移位,例如:输入“I like dancing”输出“like dancing I dancing I like”.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class QuestionOne {
/** 分隔符 */
private static final String SPLIT_CHAR = " ";
/**
* 运用JAVA语言实现对一句话的移位,例如:输入“I like dancing”输出“like dancing I dancing I like”.
*
* @throws IOException
*/
public static void main(String[] args) {
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
String[] array = null;
try {
String message = reader.readLine();
array = message.split(SPLIT_CHAR);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < array.length - 1; i++) {
for (int j = i + 1; j < array.length; j++) {
sb.append(array[i]);
sb.append(SPLIT_CHAR);
sb.append(array[j]);
sb.append(SPLIT_CHAR);
}
}
System.out.println(sb.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
}