【发布时间】:2022-01-19 08:04:33
【问题描述】:
该程序的想法是它从扫描仪获取文本除以空格。
我需要编写一个方法来从文本创建一个数组,删除重复项并返回一个只使用一次且没有重复项的单词数组。
我不知道如何创建一个新的唯一单词数组。仅使用没有 HashSet 等的简单和基本构造。*
例如:
a b a b c a b d
结果:
c d
public static String Dublicate(String text) {
String[] dublic = text.split(" ");
String result="";
for (int i = 0; i < dublic.length; i++) {
for (int j = i + 1; j < dublic.length; j++)
if (dublic[i].equals(dublic[j]))
dublic[j] = "delete";
}
for (String s: dublic) {
if (s !="delete") {
result =result + s + " ";
}
}
return result;
}
【问题讨论】:
-
欢迎来到 Stack Overflow!您似乎在要求某人为您编写一些代码。 Stack Overflow 是一个问答网站,而不是代码编写服务。请see here学习如何写出有效的问题