61 lines
1.4 KiB
Java
Executable File
61 lines
1.4 KiB
Java
Executable File
|
|
/**
|
|
* Beschreiben Sie hier die Klasse ABÜbungZuMethoden.
|
|
*
|
|
* @author (Ihr Name)
|
|
* @version (eine Versionsnummer oder ein Datum)
|
|
*/
|
|
public class ABÜbungZuMethoden
|
|
{
|
|
public static int summe(int a, int b){
|
|
return a+b;
|
|
}
|
|
public static boolean istPrim(int n){
|
|
int zähler=0;
|
|
for(int i=1;i<=n;i++){
|
|
if(n%i==0){
|
|
zähler++;
|
|
}
|
|
}
|
|
if(zähler==2){
|
|
return true;
|
|
}else{
|
|
return false;
|
|
}
|
|
}
|
|
public static boolean istPrimOptimiert(int n){
|
|
for(int i=2;i<n;i++){
|
|
if(n%i==0){
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
public static void primDoublette(int min){
|
|
boolean x=false;
|
|
while(false==x){
|
|
if(istPrimOptimiert(min)==true){
|
|
min=min+2;
|
|
if(istPrimOptimiert(min)==true){
|
|
x=true;
|
|
System.out.println(min-2+" und "+min);
|
|
}else{
|
|
min=min-2;
|
|
}
|
|
}
|
|
min++;
|
|
}
|
|
}
|
|
public static void pythagoräischeTripel(){
|
|
for(int a=1;a<=100;a++){
|
|
for(int b=1;b<=100;b++){
|
|
for(int c=1;c<=100;c++){
|
|
if(a*a+b*b==c*c){
|
|
System.out.println("a="+a+" b="+b+" c="+c);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|