Skip to content

Instantly share code, notes, and snippets.

@ssd863419
Created May 2, 2014 00:59
Show Gist options
  • Save ssd863419/accccd575e35d555f46c to your computer and use it in GitHub Desktop.
Save ssd863419/accccd575e35d555f46c to your computer and use it in GitHub Desktop.
1.2.3.4 組成無重複的三位數
package com.example.myapplication3.app;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
public class Test {
public static void main(String[] args) {
List<Integer> temp = new ArrayList<Integer>();
for (int i = 1; i <=4 ; i++) {
for (int j = 1; j <=4 ; j++) {
for (int k = 1; k <=4 ; k++) {
temp.add(i*100+j*10+k);
}
}
}
for (int a : temp) {
if (isRepeat(Integer.toString(a))){
System.out.println(a);
}
}
}
public static boolean isRepeat(String inPut){
int s1 = Integer.parseInt(inPut.substring(0,1));
int s2 = Integer.parseInt(inPut.substring(1,2));
int s3 = Integer.parseInt(inPut.substring(2,3));
if (s1 == s2 || s2 == s3 || s1 == s3) {
return false;
}else {
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment