We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey there,
I've got another quick question. I made this code, which can transfer multiple arab numbers into roman numbers. How can I "return" every roman number with a break? So that they won't clip together like they do now.
void setup() {
int[] arabicNumber = new int[3];
arabicNumber[1] = 555;
arabicNumber[2] = 888;
int numbers = arabicNumber.length;
//println(numbers);
size(200, 200);
String romanNumber = "";
getRomanNumber(arabicNumber, numbers);
} // Ende Setup
String getRomanNumber(int[] arabicNumber, int numbers) {
String romanNumber = "";
for (int i = 0; i < numbers; i++) {
println(i);
if (arabicNumber[i] >= 1000) {
print ("Bitte geben Sie nur Werte bis 999 ein");
}
while (arabicNumber[i] >= 500) {
romanNumber += "D";
arabicNumber[i] -= 500;
}
while (arabicNumber[i] >= 100) {
romanNumber += "C";
arabicNumber[i] -= 100;
}
while (arabicNumber[i] >= 50) {
romanNumber += "L";
arabicNumber[i] -= 50;
}
while (arabicNumber[i] >= 10) {
romanNumber += "X";
arabicNumber[i] -= 10;
}
while (arabicNumber[i] >= 5) {
romanNumber += "V";
arabicNumber[i] -= 5;
}
while (arabicNumber[i] >= 1) {
romanNumber += "I";
arabicNumber[i] -= 1;
}
}
romanNumber = romanNumber.replace("DCCCC", "CM"); //Siehe Tabellen auf http://www.roemische-zahlen.net/
romanNumber = romanNumber.replace("CCCC", "CD");
romanNumber = romanNumber.replace("LXXXX", "XC");
romanNumber = romanNumber.replace("XXXX", "XL");
romanNumber = romanNumber.replace("VIIII", "IX");
romanNumber = romanNumber.replace("IIII", "IV");
fill (#EA0E49);
text (romanNumber, 30, 30);
return romanNumber;
}
Best Regards, iSpectra
Answers
Methinks getRomanNumber() shoulda focused on 1 conversion at a time. ~:>
As said, you should separate concerns:
Ok, I understand. But how can I let the caller display the returned value?
Using text(), as you did, with the returned value, after the call...
Right, OMG ROFL. How did I miss that!? Thank you very much!
Anyways, my tweaked version (w/ negative roman numbers & 3999 limit!) I was doing a while ago: L-)