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

Status
Not open for further replies.

Heks

Forum Veteran
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
 
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.

About this Thread

  • 3
    Replies
  • 627
    Views
  • 2
    Participants
Last reply from:
Heks

Trending Topics

Online now

Members online
1,309
Guests online
3,476
Total visitors
4,785

Forum statistics

Threads
2,305,826
Posts
29,168,073
Members
1,195,464
Latest member
tibolok
Back
Top