运用JAVA语言实现对一句话的移位,例如:输入“I like dancing”输出“like dancing I dan
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/19 04:11:29
运用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();
}
}
}
再问: 输出的结果有点不对啊,我自己再修改修改吧,分还是给你了,谢谢!
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();
}
}
}
再问: 输出的结果有点不对啊,我自己再修改修改吧,分还是给你了,谢谢!
运用JAVA语言实现对一句话的移位,例如:输入“I like dancing”输出“like dancing I dan
同义句转换 I like painting but I like dancing better .I ----- dan
I like dancing and sing 对还是I like dancing and singing对?
I like dancing and singing
________singing,i also like dancing
i like dancing to the music
i like singing out of dancing
I Don T Feel Like Dancing 歌词
I like singing.She likes dancing.是什么形式的句子
I enjoy dancing to music对还是I like dance to music对
对括号部分提问:① I can join the dance club (because I like dancing)
I like singing.I like dancing,too.(改为同义句) I like singing.I (