Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,27 @@
import java.util.HashSet;
public class Happy{
public static boolean happy(long number){
long m = 0;
int digit = 0;
HashSet<Long> cycle = new HashSet<Long>();
while(number != 1 && cycle.add(number)){
m = 0;
while(number > 0){
digit = (int)(number % 10);
m += digit*digit;
number /= 10;
}
number = m;
}
return number == 1;
}
public static void main(String[] args){
for(long num = 1,count = 0;count<8;num++){
if(happy(num)){
System.out.println(num);
count++;
}
}
}
}

View file

@ -0,0 +1,26 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
public class HappyNumbers {
public static void main(String[] args) {
for (int current = 1, total = 0; total < 8; current++)
if (isHappy(current)) {
System.out.println(current);
total++;
}
}
public static boolean isHappy(int number) {
HashSet<Integer> cycle = new HashSet<>();
while (number != 1 && cycle.add(number)) {
List<String> numStrList = Arrays.asList(String.valueOf(number).split(""));
number = numStrList.stream().map(i -> Math.pow(Integer.parseInt(i), 2)).mapToInt(i -> i.intValue()).sum();
}
return number == 1;
}
}