🔒 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
  • 629
    Views
  • 2
    Participants
Last reply from:
Heks

Trending Topics

Online now

Members online
379
Guests online
2,738
Total visitors
3,117

Forum statistics

Threads
2,317,768
Posts
29,192,785
Members
1,181,628
Latest member
enmx
Back
Top