What's new

Closed Convert numbers into roman numeral and word as well. help

Status
Not open for further replies.

Heks

Forum Veteran
Established
Joined
Dec 9, 2017
Posts
3,383
Solutions
1
Reaction
760
Points
996
So may case study kasi ako mga papsikil, mag iinput ng number from 1 - 3000 and dapat ang output nya ay words at roman numerals using if else and switch case only none other than that. Ask lng sana ako kung may alam kayo na short method?
Kasi kung mano mano ko napaka haba ng code. Nababasa ko na pwede gamitin mudulos, kaso d ko pa alam ung structure nya ..

Ps. Sa Php nga pala mga papsikil ko ginagawa

Salamatttt
 
If($number ==1) {
Echo "ONE, I"
}

Pag ganito kasi napakahaba mga master huhu
 
public static String IntegerToRomanNumeral(int input) {
if (input < 1 || input > 3999)
return "Invalid Roman Number Value";
String s = "";
while (input >= 1000) {
s += "M";
input -= 1000; }
while (input >= 900) {
s += "CM";
input -= 900;
}
while (input >= 500) {
s += "D";
input -= 500;
}
while (input >= 400) {
s += "CD";
input -= 400;
}
while (input >= 100) {
s += "C";
input -= 100;
}
while (input >= 90) {
s += "XC";
input -= 90;
}
while (input >= 50) {
s += "L";
input -= 50;
}
while (input >= 40) {
s += "XL";
input -= 40;
}
while (input >= 10) {
s += "X";
input -= 10;
}
while (input >= 9) {
s += "IX";
input -= 9;
}
while (input >= 5) {
s += "V";
input -= 5;
}
while (input >= 4) {
s += "IV";
input -= 4;
}
while (input >= 1) {
s += "I";
input -= 1;
}
return s;
}

nakita ko lang sa stackoverflow
 
public static String IntegerToRomanNumeral(int input) {
if (input < 1 || input > 3999)
return "Invalid Roman Number Value";
String s = "";
while (input >= 1000) {
s += "M";
input -= 1000; }
while (input >= 900) {
s += "CM";
input -= 900;
}
while (input >= 500) {
s += "D";
input -= 500;
}
while (input >= 400) {
s += "CD";
input -= 400;
}
while (input >= 100) {
s += "C";
input -= 100;
}
while (input >= 90) {
s += "XC";
input -= 90;
}
while (input >= 50) {
s += "L";
input -= 50;
}
while (input >= 40) {
s += "XL";
input -= 40;
}
while (input >= 10) {
s += "X";
input -= 10;
}
while (input >= 9) {
s += "IX";
input -= 9;
}
while (input >= 5) {
s += "V";
input -= 5;
}
while (input >= 4) {
s += "IV";
input -= 4;
}
while (input >= 1) {
s += "I";
input -= 1;
}
return s;
}

nakita ko lang sa stackoverflow
Salamat paps pero like what ive said if else and switch lng . Pero salamat paps
 
Status
Not open for further replies.
Back
Top