first commit
This commit is contained in:
38
BP/GKD.java
Normal file
38
BP/GKD.java
Normal 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;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user