Skip to content

Instantly share code, notes, and snippets.

@paddya
Created November 11, 2012 12:23
Show Gist options
  • Save paddya/4054766 to your computer and use it in GitHub Desktop.
Save paddya/4054766 to your computer and use it in GitHub Desktop.
import Prog1Tools.IOTools;
public class P15
{
public static void main (String [] args)
{
int i;
do{
i = IOTools.readInt("Positive ganze Zahl: ");
}while(i<=0);
// diese do-while-Schleife sorgt dafür, dass wir eine positive ganze Zahl haben
int x;
String normal = ""; // String normal wird definiert
String reversed = "";
System.out.print("Zerlegt rückwärts: ");
while(i>0){
x = i % 10; // x entspricht der letzten Zahl von i
String current = "";
switch(x){
case 0:
current = "Null"; break;
case 1:
current = "Eins"; break;
case 2:
current = "Zwei"; break;
case 3:
current = "Drei"; break;
case 4:
current = "Vier"; break;
case 5:
current = "Fünf"; break;
case 6:
current = "Sechs"; break;
case 7:
current = "Sieben"; break;
case 8:
current = "Acht"; break;
case 9:
current = "Neun"; break;
}
normal = current + " " + normal;
reversed = reversed + " " + current;
i = i / 10; // von i wird die letzte Zahl abgehängt
}
System.out.println("Zerlegt rückwärts: " + reversed);
System.out.println("Zerlegt vorwärts: " + normal);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment