Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Zahlen {
- public static boolean istPrimLoop(int p) {
- if (p > 1) {
- boolean istPrim = true;
- for(int i = 2; i < p; i++) {
- if(p%i == 0) {
- istPrim = false;
- }
- }
- return istPrim;
- }
- else {
- return false;
- }
- }
- public static boolean istPrimRek(int p) {
- return istPrimHilfe(p, 2);
- }
- public static boolean istPrimHilfe(int p, int t) {
- if(p%t == 0 && t > 1 && p != 2 || p < 2) {
- return false;
- }
- else if (t + 1 < p) {
- return istPrimHilfe(p, t+1);
- }
- else {
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement