public static void main(String[] args) {
Set<String> numberList = new HashSet<String>();
for (int i = 1; i <= 4; i++) {
getNumber(numberList, i + "");
}
List<String> numbers = new ArrayList<String>(numberList);
Collections.sort(numbers);
System.out.println(numbers);
System.out.println(numbers.size());
}
private static void getNumber(Set<String> numberList, String first) {
String second;
String third;
second = "";
third = "";
for (int i = 1; i <= 4; i++) {
second = "" + i;
if (second.equals(first))
continue;
for (int j = 1; j <= 4; j++) {
third = "" + j;
if (third.equals(first))
continue;
if (!second.equals(third)) {
numberList.add(first + second + third);
}
}
}
}
</pre><pre name="code" class="java">闲着没有事情做就刷刷简单的题目,额,自己的实现比较麻烦啊。看了一下别人的实现还是很简单的。
比较标准的答案:
<pre name="code" class="java"> public static void main(String[] args) { int i = 0; int j = 0; int k = 0; int t = 0; for (i = 1; i <= 4; i++) for (j = 1; j <= 4; j++) for (k = 1; k <= 4; k++) if (i != j && j != k && i != k) { t += 1; System.out.println(i * 100 + j * 10 + k); } System.out.println(t); }
总结:自己体会到的就是不管多简单,也要自己试试,很可能收获了另一种思维。
还有就是没有经过思考的东西比较容易忘记。遇到了先自己思考,自己应该如何做,然后在参考别人的做法。
</pre><pre name="code" class="java">