Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package AlgorithmenAllgemein;
- import util.ReadUtil;
- public class ggT {
- private static int ggt(int zahl1, int zahl2) {
- while (zahl2 != 0) {
- if (zahl1 > zahl2) {
- zahl1 = zahl1 - zahl2;
- } else {
- zahl2 = zahl2 - zahl1;
- }
- }
- return zahl1;
- }
- public static void main(String[] args) {
- int n = ReadUtil.nextInt("ggT 1: ");
- int m = ReadUtil.nextInt("ggT 2: ");
- int ggT1 = n;
- int ggT2 = m;
- int ergebnis = ggt(ggT1, ggT2);
- System.out.println("Der GGT von " + ggT1 + " und " + ggT2 + " ist " + ergebnis);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement