This commit is contained in:
Your Name
2023-10-03 23:28:51 +02:00
parent 9a83c28137
commit 42f2899bbf
162 changed files with 9 additions and 13 deletions

38
WS22_23/BP/GKD.java Normal file
View File

@@ -0,0 +1,38 @@
import java.util.*;
class GKD{
public int c;
public static void main(String[] args){
System.out.println("a und b eingeben(durch Leerzeichen getrennt)");
Scanner sc = new Scanner(System.in);
int input1 = sc.nextInt();
int input2 = sc.nextInt();
System.out.println("Das Ergebniss von modulo ist: " + modulo(input1,input2));
System.out.println("Das Ergebnis von gdk ist: "+ gdk(input1,input2));
// ergebnis von gdk(10,25) ist 5
}
public static int modulo(int a, int b){
return a % b;
}
public static int moduloSicher(int a, int b){
if(a > 0 && b > 0){
return a % b;
}
else if(b == 0 && a > 0){
return a;
}
else if(a == 0){
return b;
}
return 0;
}
public static int gdk(int a, int b){
while(a != b){
int c = moduloSicher(a,b);
a = b;
b = c;
}
return a;
}
}