Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sophie Germen Number With Java
import java.util.ArrayList;
import java.util.List;
//Çözüldü-Solved
public class Sophie_Germen {
//A bir asal sayi iken 2.a+1 sayısıda asal sayı oluyorsa a sayısına Sophie Germen asalı denir.
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
for (int i = 2; i < 100; i++) {
boolean divide = false;
if (i == 2) {
list.add(i);
}
else {
for (int j = 2; j < i; j++) {
if (i % j == 0) {
divide = true;
break;
}
}
int second = (2 * i) + 1;
if (divide == false) {
for (int j = 2; j < second; j++) {
if (second % j == 0) {
divide = true;
}
}
if (divide == false) {
list.add(i);
}
}
}
}
System.out.println(list);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment