У меня есть два массива:
String common[] = {"also", "bad", "because", "but", "by", "crazy", "day", "for", "from", "good", "how", "just", "most", "no", "other", "people", "some", "speak", "speech", "strange", "talk", "them", "then", "think", "way", "what", "where", "who", "why", "with", "yes", "you"};
и
String jabber[] = {"ancient", "ballerina", "banana", "bankroll", "berserker", "birthplace", "blathering", "bouncy", "boutique", "candelabra", "cannibal", "capacitor", "circuit", "crash", "craven", "creepy", "dance", "dangerous", "daring", "dastardly", "download", "dragon", "ego", "evaluate", "feudal", "fiery", "flux", "funky", "ghostly", "glass", "gold", "grizzly", "hatch", "Hogwarts", "horn", "impure", "jump", "muscle", "near", "nicest", "omnivore", "parasite", "patronus", "punch", "salad", "savage", "seven", "shameful", "since", "slither", "sonic", "spaceship", "square", "tango", "tape", "throughout", "upon", "volcano"};
У меня есть сканер, который принимает ввод пользователя, допустим.Учитывая строку в качестве входных данных, этот метод должен иметь возможность переключать общее слово с jabberword для каждого вхождения для одного и того же общего слова: например, если ввод:
также также
, то, скажем, он выбираетчтобы заменить также на древний, он должен сказать
древний древний древний
Вот мой код:
public static String getJabberwordyResponse(String line) {
String[] common = {"also", "bad", "because", "but", "by", "crazy", "day", "for", "from", "good", "how", "just", "most", "no", "other", "people", "some", "speak", "speech", "strange", "talk", "them", "then", "think", "way", "what", "where", "who", "why", "with", "yes", "you"};
String[] jabber = {"ancient", "ballerina", "banana", "bankroll", "berserker", "birthplace", "blathering", "bouncy", "boutique", "candelabra", "cannibal", "capacitor", "circuit", "crash", "craven", "creepy", "dance", "dangerous", "daring", "dastardly", "download", "dragon", "ego", "evaluate", "feudal", "fiery", "flux", "funky", "ghostly", "glass", "gold", "grizzly", "hatch", "Hogwarts", "horn", "impure", "jump", "muscle", "near", "nicest", "omnivore", "parasite", "patronus", "punch", "salad", "savage", "seven", "shameful", "since", "slither", "sonic", "spaceship", "square", "tango", "tape", "throughout", "upon", "volcano"};
for(int i = 0; i < common.length; i++) {
int j = (i >= jabber.length - 1) ? 0 : i;
line.replace(common[i], jabber[i]);
}
return line;
}
Мысли?