1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TestPeriode;
/**
*
* @author gilles
*/
public class Main {
static int Tab[] = {1, 0, 1, 1, 0, 1, 1, 0, 1};
static int n = Tab.length;
static boolean Test(int i, int k) {
for (int h = k; h < n; h += k) {
if (Tab[i] != Tab[i + h]) {
return false;
}
}
return true;
}
static void FindPeriode() {
boolean success = true;
for (int k = 1; k <= n; k++) {
if (n % k != 0) {
continue;
} else {
success = true;
for (int j = 0; j <= k; j++) {
if (!Test(j, k)) {
success = false;
}
break;
}
if (success) {
System.out.print(k);
break;
}
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
FindPeriode();
}
} |