Created
December 1, 2017 10:32
-
-
Save KurzGedanke/4626916709ba764de0e7f8293336fb24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Scheiß Kommentare | |
*/ | |
public class Zahldarstellung { | |
public static boolean checkBasis(long zahl, int basis) { | |
System.out.println("Zahl: " + zahl); | |
return zahl % 10 <= basis || zahl == 0 && checkBasis(zahl / 10, basis); | |
} | |
public static long hornerSchema(long zahl, int basis) { | |
return zahl < 10 ? | |
(long) zahl : | |
hornerSchema(zahl / 10, basis) * basis + (long) zahl % 10; | |
} | |
public static long makeMeBasis(long zahl, int basis) { | |
return zahl == 0 ? 0 : makeMeBasis(zahl / basis, basis) * 10 + (zahl % basis); | |
} | |
public static long addiere(long zahlEins, long zahlZwei, int basis) { | |
return checkBasis(zahlEins, basis) && checkBasis(zahlZwei, basis) ? | |
makeMeBasis((hornerSchema(zahlEins, basis) + hornerSchema(zahlZwei, basis)), basis) | |
: -1; | |
} | |
public static void main(String[] args) { | |
System.out.println(addiere(773, 1239, 8)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment