Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. Meine Fucking Lösung:
  2. public class ggT2 {
  3.  
  4. /**
  5. * @param args
  6. */
  7. public static void main(String[] args) {
  8. // TODO Auto-generated method stub
  9.  
  10. int x = 43158, y = 26364;
  11.  
  12. System.out.print("Größter gemeinsamer Teiler");
  13.  
  14. while ((x != 0) || (y != 0));
  15. {
  16. if (x > y)
  17. {
  18. x = x - y;
  19. }
  20. else
  21. {
  22. y = y - x;
  23. }
  24.  
  25. }
  26.  
  27. if (x > y)
  28. {
  29. System.out.print(x);
  30. }
  31. else
  32. {
  33. System.out.print(y);
  34. }
  35.  
  36. }
  37.  
  38. }
  39.  
  40.  
  41.  
  42. "Musterlösung":
  43. /**
  44. * groesster gemeinsamer Teiler ggT
  45. */
  46. public class ggT {
  47. public static void main (String[] args) {
  48. // Beispielwerte
  49. int x = 43158;
  50. int y = 26364;
  51.  
  52. // gebe die Werte von x und y aus
  53. System.out.print ("Der ggT von " + x + " und " + y + " ist ");
  54.  
  55. if(x == 0) {
  56. // gebe das Ergebnis / den ggT aus
  57. System.out.println (y);
  58. } else {
  59. while (y != 0) {
  60. if (x > y) {
  61. x = x - y;
  62. } else {
  63. y = y - x;
  64. }
  65. }
  66. // das Verfahren brach ab und in x (und y) steht das Resultat
  67. System.out.println (x);
  68. }
  69.  
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement