Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Meine Fucking Lösung:
- public class ggT2 {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int x = 43158, y = 26364;
- System.out.print("Größter gemeinsamer Teiler");
- while ((x != 0) || (y != 0));
- {
- if (x > y)
- {
- x = x - y;
- }
- else
- {
- y = y - x;
- }
- }
- if (x > y)
- {
- System.out.print(x);
- }
- else
- {
- System.out.print(y);
- }
- }
- }
- "Musterlösung":
- /**
- * groesster gemeinsamer Teiler ggT
- */
- public class ggT {
- public static void main (String[] args) {
- // Beispielwerte
- int x = 43158;
- int y = 26364;
- // gebe die Werte von x und y aus
- System.out.print ("Der ggT von " + x + " und " + y + " ist ");
- if(x == 0) {
- // gebe das Ergebnis / den ggT aus
- System.out.println (y);
- } else {
- while (y != 0) {
- if (x > y) {
- x = x - y;
- } else {
- y = y - x;
- }
- }
- // das Verfahren brach ab und in x (und y) steht das Resultat
- System.out.println (x);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement