java ,句子中的单词按顺序输出老师出了一个别扭的题.一共四个英文句子1 The bus was crowded and no vacant seat was to be found.6 5 2 9 12 1 4 11 10 7 3 82 I will never come to such an unpleasant place again.2 8 6 10 9 1 5 3 7
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/14 18:56:55
java ,句子中的单词按顺序输出老师出了一个别扭的题.一共四个英文句子1 The bus was crowded and no vacant seat was to be found.6 5 2 9 12 1 4 11 10 7 3 82 I will never come to such an unpleasant place again.2 8 6 10 9 1 5 3 7
java ,句子中的单词按顺序输出
老师出了一个别扭的题.一共四个英文句子
1 The bus was crowded and no vacant seat was to be found.
6 5 2 9 12 1 4 11 10 7 3 8
2 I will never come to such an unpleasant place again.
2 8 6 10 9 1 5 3 7 4
3 My family shall not want for anything as long as I live.
7 2 12 10 3 8 4 9 6 11 5 1
4 I have just been to the hospital to inquire after Mr.A.
11 4 2 9 7 10 1 6 3 5 8
首先,在屏幕上输出这四句话,然后问用户选择哪句话,然后 按句子下面的数字,一次输出对应位置的单词.如 输出3 ,则显示
anything family live as shall as not long for I want My
java ,句子中的单词按顺序输出老师出了一个别扭的题.一共四个英文句子1 The bus was crowded and no vacant seat was to be found.6 5 2 9 12 1 4 11 10 7 3 82 I will never come to such an unpleasant place again.2 8 6 10 9 1 5 3 7
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Test test1 = new Test("The bus was crowded and no vacant seat was to be found.",6,5,2,9,12,1,4,11,10,7,3,8);
Test test2 = new Test("I will never come to such an unpleasant place again.",2,8,6,10,9,1,5,3,7,4);
Test test3 = new Test("My family shall not want for anything as long as I live.",7,2,12,10,3,8,4,9,6,11,5,1);
Test test4 = new Test("I have just been to the hospital to inquire after Mr.A.",11,4,2,9,7,10,1,6,3,5,8);
Test[] tests = {test1,test2,test3,test4};
for (int i = 0; i < tests.length; i++) {
System.out.println(i+1+" : "+tests[i].getSentence());
}
System.out.println("请选择你要输出的话:");
int i = input.nextInt();
System.out.println(tests[i-1]);
}
private String sentence;
private int[] indexs;
public int[] getIndexs() {
return indexs;
}
public void setIndexs(int[] indexs) {
this.indexs = indexs;
}
public Test() { }
public Test(String sentence, int...indexs) {
this.sentence = sentence;
this.indexs = indexs;
}
public String getSentence() {
return sentence;
}
public void setSentence(String sentence) {
this.sentence = sentence;
}
public String toString() {
String[] words = sentence.split(" ");
StringBuffer newSentence = new StringBuffer();
for (int i = 0; i < indexs.length; i++) {
newSentence.append(words[indexs[i]-1]+" ");
}
return newSentence.toString();
}
}