Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,27 @@
|
|||
public class SelfDescribingNumbers{
|
||||
public static boolean isSelfDescribing(int a){
|
||||
String s = Integer.toString(a);
|
||||
for(int i = 0; i < s.length(); i++){
|
||||
String s0 = s.charAt(i) + "";
|
||||
int b = Integer.parseInt(s0); // number of times i-th digit must occur for it to be a self describing number
|
||||
int count = 0;
|
||||
for(int j = 0; j < s.length(); j++){
|
||||
int temp = Integer.parseInt(s.charAt(j) + "");
|
||||
if(temp == i){
|
||||
count++;
|
||||
}
|
||||
if (count > b) return false;
|
||||
}
|
||||
if(count != b) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
for(int i = 0; i < 100000000; i++){
|
||||
if(isSelfDescribing(i)){
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue