Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -0,0 +1,26 @@
|
|||
import java.util.stream.IntStream;
|
||||
public class NarcissisticNumbers {
|
||||
static int numbersToCalculate = 25;
|
||||
static int numbersCalculated = 0;
|
||||
|
||||
public static void main(String[] args) {
|
||||
IntStream.iterate(0, n -> n + 1).limit(Integer.MAX_VALUE).boxed().forEach(i -> {
|
||||
int length = i.toString().length();
|
||||
int addedDigits = 0;
|
||||
|
||||
for (int count = 0; count < length; count++) {
|
||||
int value = Integer.parseInt(String.valueOf(i.toString().charAt(count)));
|
||||
addedDigits += Math.pow(value, length);
|
||||
}
|
||||
|
||||
if (i == addedDigits) {
|
||||
numbersCalculated++;
|
||||
System.out.print(addedDigits + " ");
|
||||
}
|
||||
|
||||
if (numbersCalculated == numbersToCalculate) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue