/**
 * AnyServer -- Praktikum Experimentierkasten -- ADS
 *
 * @author E. Mumprecht
 * @version 1.0 -- Geruest fuer irgendeinen Server
 */
package ch.zhaw.ads;

import java.util.Scanner;
import java.io.ByteArrayInputStream;


public class KGVServer implements CommandExecutor {

    //----- Dies implementiert das CommandExecutor Interface.
    @Override
    public String execute(String s) {
        Scanner scanner = new Scanner(new ByteArrayInputStream(s.getBytes()));
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        return Integer.toString(kgv(a,b)) + "\n";
    }

    public int kgv(int a, int b) {
        return a * b / ggt(a, b);
    }

    private Integer ggt(int a, int b) {
        if (a > b) return ggt(a-b,b);
        else if (a < b) return ggt(a,b-a);
        else return a;
    }

}//AnyServer
