Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.FisheyLP.IntToString;
- public class Umrechner {
- public static String[] einser = new String[] { "null", "ein", "zwei",
- "drei", "vier", "fünf", "sechs", "sieben", "acht", "neun" };
- public static String[] zehner = new String[] { null, "zehn", "zwanzig",
- "dreissig", "vierzig", "fünfzig", "sechzig", "siebzig", "achtzig",
- "neunzig" };
- public String convertToString(int i) {
- String text = "";
- boolean isMinus = i < 0;
- if (isMinus) {
- i = Math.abs(i);
- }
- if (containsHunderter(i)) {
- text = einser[getHunderter(i)] + "hundert";
- if (containsZehner(i)) {
- text = einser[getHunderter(i)] + "hundert"
- + zehner[getZehner(i)];
- String zusatz = null;
- if (getEinser(i) == 1)
- zusatz = "elf";
- if (getEinser(i) == 2)
- zusatz = "zwölf";
- if (containsEinser(i)) {
- if (getZehner(i) < 2) {
- if (zusatz == null) {
- text = einser[getHunderter(i)] + "hundert"
- + einser[getEinser(i)]
- + zehner[getZehner(i)];
- } else {
- text = einser[getHunderter(i)] + "hundert" + zusatz;
- }
- } else {
- text = einser[getHunderter(i)] + "hundert"
- + einser[getEinser(i)] + "und"
- + zehner[getZehner(i)];
- }
- }
- } else {
- text = einser[getHunderter(i)] + "hundert"
- + einser[getEinser(i)];
- }
- text = text.replace("eins", "ein");
- } else if (containsZehner(i)) {
- text = zehner[getZehner(i)];
- if (containsEinser(i)) {
- if (i == 11)
- return "Elf";
- if (i == 12)
- return "Zwölf";
- if (getZehner(i) < 2) {
- text = einser[getEinser(i)] + zehner[getZehner(i)];
- } else {
- text = einser[getEinser(i)] + "und" + zehner[getZehner(i)];
- }
- }
- } else {
- text = einser[getEinser(i)];
- }
- if (text.endsWith("ein")) {
- text = text + "s";
- }
- text = text.replace("achtzig", "achzig");
- text = text.substring(0, 1).toUpperCase() + text.substring(1);
- if (isMinus) {
- text = "Minus " + text;
- }
- return text;
- }
- public static int getEinser(int i) {
- String str = Integer.toString(i);
- String value = str.split("")[str.length()];
- return Integer.parseInt(value);
- }
- public static int getZehner(int i) {
- String str = Integer.toString(i);
- String value = str.split("")[str.length() - 1];
- return Integer.parseInt(value);
- }
- public static int getHunderter(int i) {
- String str = Integer.toString(i);
- String value = str.split("")[str.length() - 2];
- return Integer.parseInt(value);
- }
- public static boolean containsEinser(int i) {
- String text = Integer.toString(i);
- return !text.endsWith("0");
- }
- public static boolean containsZehner(int i) {
- String text = Integer.toString(i);
- if (text.length() < 2)
- return false;
- return !text.split("")[text.length() - 1].contains("0");
- }
- public static boolean containsHunderter(int i) {
- String text = Integer.toString(i);
- if (text.length() < 3)
- return false;
- return !text.split("")[text.length() - 2].contains("0");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment