according to me its ok but is calculating wrong values in
program to calculate roman numbers .....i.e roman number calculator
import java.util.*;
import java.io.*;
class romancalci {
public static void main(String args[])throws IOException {
int decimal1 = 0;int decimal2=0;
Scanner input=new Scanner(System.in);
System.out.print("Enter a Roman Number 1st: ");
String roman1 = input.next();
System.out.println("Enter a Roman Number 2nd: ");
String roman2=input.next();
String romanNumeral1 = roman1.toUpperCase();
String romanNumeral2=roman2.toUpperCase();
int x = 0;int result=0;int largest=0;int number=0;
int l1=romanNumeral1.length();
int l2=romanNumeral2.length();
String numeral1=romanNumeral1;
String numeral2=romanNumeral2;
String s="IC";
String s3="IVC";
String newNumeral = numeral1.replace("XL", "XXXX"); // Replaces XL with XXXX
String newNumeral2 = newNumeral.replace("XC", "LXXXX"); // Replaces XC with LXXXX
String newNumeral3 = newNumeral2.replace("CD", "CCCC"); // Replaces CD with CCCC
String newNumeral4 = newNumeral3.replace("CM", "DCCCC"); // Replaces CM with DCCC
String newNumeral5 = newNumeral4.replace("IV", "IIII"); // Replaces IV with IIII
String newNumeral6 = newNumeral5.replace("IX", "VIIII");
l1=newNumeral6.length();
String newNumeralz = numeral2.replace("XL", "XXXX"); // Replaces XL with XXXX
String newNumeralz2 = newNumeralz.replace("XC", "LXXXX"); // Replaces XC with LXXXX
String newNumeralz3 = newNumeralz2.replace("CD", "CCCC"); // Replaces CD with CCCC
String newNumeralz4 = newNumeralz3.replace("CM", "DCCCC"); // Replaces CM with DCCC
String newNumeralz5 = newNumeralz4.replace("IV", "IIII"); // Replaces IV with IIII
String newNumeralz6 = newNumeralz5.replace("IX", "VIIII");
l2=newNumeralz6.length();
if(newNumeral6.equals(s))
{
System.out.println("enter the correct roman value 1 in place of IC");
newNumeral6="0";
}
do {
char convert1 = newNumeral6.charAt(x);
switch (convert1) {
case 'M':
decimal1 += 1000;
break;
case 'D':
decimal1 += 500;
break;
case 'C':
decimal1 += 100;
break;
case 'L':
decimal1 += 50;
break;
case 'X':
decimal1 += 10;
break;
case 'V':
decimal1 += 5;
break;
case 'I':
decimal1 += 1;
break;
}
x++;
} while (x < l1);
System.out.println("Decimal Number1 is: " + decimal1);
x=0;
if(newNumeralz6.equals("ic"))
{
System.out.println("enter the correct roman value 2 in place of IC");
newNumeralz6="0";
}
do {
char convert2 = newNumeralz6.charAt(x);
switch (convert2) {
case 'M':
decimal2 += 1000;
break;
case 'D':
decimal2 += 500;
break;
case 'C':
decimal2 += 100;
break;
case 'L':
decimal2 += 50;
break;
case 'X':
decimal2 += 10;
break;
case 'V':
decimal2 += 5;
break;
case 'I':
decimal2 += 1;
break;
}
x++;
} while (x < l2);
System.out.println("Decimal Number2 is: " + decimal2);
System.out.println("enter the choice for calculating \n 1 for addition \n 2 for subtraction \n 3 for multiplication");
int choice=input.nextInt();
switch(choice)
{
case 1:
result=decimal1+decimal2;
System.out.println("the calculated result in integer is= "+ result);
break;
case 2:
result=decimal1-decimal2;
System.out.println("the calculated result in integer is= "+ result);
break;
case 3:
result=decimal1*decimal2;
System.out.println("the calculated result in integer is= "+ result);
break;
default:
System.out.println("enter the correct choice");
}
number=result;
String roman="";
while(number>=1000){
roman += "M";
number-=1000;
}
while(number>=900){
roman += "CM";
number-=900;
}
while(number>=500){
roman += "D";
number-=500;
}
while(number>=400){
roman += "CD";
number-=400;
}
while(number>=100){
roman += "C";
number-=100;
}
while(number>=90){
roman += "XC";
number-=90;
}
while(number>=50){
roman += "L";
number-=50;
}
while(number>=40){
roman += "XL";
number-=40;
}
while(number>=10){
roman += "X";
number-=10;
}
while(number>=9){
roman += "IX";
number-=9;
}
while(number>=5){
roman += "V";
number-=5;
}
while(number>=4){
roman += "IV";
number-=4;
}
while(number>=1){
roman += "I";
number-=1;
}
System.out.println("the final result in roman ="+ roman);
}
}
View Answers
Related Tutorials/Questions & Answers:
Advertisements
reply me its urgent - Java Beginnersreply
me its urgent Hi friends
I am facing problem in my application in this type please help
me
i am using database mysql5.0 version...'@'localhost' (using password: YES)"
please tell
me what is the error....
its its urgent for me - Development processits urgent for me Hi All,
this is kalavathi,i am new to alfresco.present i am using alfresco3.9b version.my problem is i was writing code in java... is the problem .can u tell
me i will send my total code and error exception also.
import
Ple help me its very urgentPle help
me its very urgent Hi..
I have one string
1)'2,3,4'
i want do like this
'2','3','4'
ple help
me very urgent
Please help me... its very urgentPlease help
me...
its very urgent Please send
me a java code to check whether INNODB is installed in mysql...
If it is there, then we need to calculate the number of disks used by mysql
pls help me sir its urgentpls help
me sir
its urgent thanks for reply,
but i am getting this error pls help
me its urgent
type Exception report
message
description The server encountered an internal error () that prevented it from
wrong year = [NSDate date];
NSLog(@"%@", [df stringFromDate:date]);
return;
Its giving
me wrong year..ADS_TO_REPLACE_1
I think u are using other calendar
Check...
wrong year hello
I m using the following code:
NSDateFormatter
Plz reply me sir Its urgent - JSP-ServletPlz reply
me sir
Its urgent Respected Sir/madam,
I am R.Ragavendran..Actuaaly,I request you to remember the code which you have provided for
me using radio buttons..
You have used the following syntax for checking whether
Calculating current ExperienceCalculating current Experience I have 2 dates one is the current date and another is join date f an employee i need to calculate the current experience as in years months and days can any one help
me pls
ModuleNotFoundError: No module named 'ok'ModuleNotFoundError: No module named '
ok' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
ok'
How to remove the ModuleNotFoundError: No module named '
ok' error
ModuleNotFoundError: No module named 'wrong'ModuleNotFoundError: No module named '
wrong' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
wrong'
How to remove the ModuleNotFoundError: No module named '
wrong'
Java Program for Calculating MarksJava Program for
Calculating Marks Hi Everyone,
I have a assignment that requires
me to a write simple java program that will calculate marks... of how to do this. Please someone help
me with this assignment.
Thank you very
Java Program for Calculating MarksJava Program for
Calculating Marks Hi Everyone,
I have a assignment that requires
me to a write simple java program that will calculate marks... of how to do this. Please someone help
me with this assignment.
Thank you very
Java Program for Calculating MarksJava Program for
Calculating Marks Hi Everyone,
I have a assignment that requires
me to a write simple java program that will calculate marks... of how to do this. Please someone help
me with this assignment.
Thank you very
Java Program for Calculating MarksJava Program for
Calculating Marks Hi Everyone,
I have a assignment that requires
me to a write simple java program that will calculate marks... of how to do this. Please someone help
me with this assignment.
Thank you very
What is wrong with this lineWhat is
wrong with this line What is
wrong with this line
JOptionPane.showMessageDialog(null? for Using Lewandowski's Savings pgrm!");
from
if (input.equals("exit") || input.equals("Exit"))
{
JOptionPane.showMessageDialog
ModuleNotFoundError: No module named 'http-ok'ModuleNotFoundError: No module named 'http-
ok' Hi,
My Python...-
ok'
How to remove the ModuleNotFoundError: No module named 'http-
ok... to install padas library.
You can install http-
ok python with following command
ModuleNotFoundError: No module named 'ok-anime'ModuleNotFoundError: No module named '
ok-anime' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
ok-anime'
How to remove the ModuleNotFoundError: No module named '
ok-anime
ModuleNotFoundError: No module named 'ok-api'ModuleNotFoundError: No module named '
ok-api' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
ok-api'
How to remove the ModuleNotFoundError: No module named '
ok-api'
ModuleNotFoundError: No module named 'ok-deploy'ModuleNotFoundError: No module named '
ok-deploy' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
ok-deploy'
How to remove the ModuleNotFoundError: No module named '
ok ModuleNotFoundError: No module named 'ok-esputnik'ModuleNotFoundError: No module named '
ok-esputnik' Hi,
My Python... '
ok-esputnik'
How to remove the ModuleNotFoundError: No module named '
ok... you have to install padas library.
You can install
ok-esputnik python
ModuleNotFoundError: No module named 'ok-redis'ModuleNotFoundError: No module named '
ok-redis' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
ok-redis'
How to remove the ModuleNotFoundError: No module named '
ok-redis
ModuleNotFoundError: No module named 'pytest-ok'ModuleNotFoundError: No module named 'pytest-
ok' Hi,
My Python... 'pytest-
ok'
How to remove the ModuleNotFoundError: No module named 'pytest-
ok' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'djadmin-ok'ModuleNotFoundError: No module named 'djadmin-
ok' Hi,
My Python... 'djadmin-
ok'
How to remove the ModuleNotFoundError: No module named 'djadmin-
ok' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'http-ok'ModuleNotFoundError: No module named 'http-
ok' Hi,
My Python...-
ok'
How to remove the ModuleNotFoundError: No module named 'http-
ok... to install padas library.
You can install http-
ok python with following command
User LogIn According to RoleUser LogIn
According to Role User login
According to role but output will be always displayed in a single page.. but content will change
according role
what is wrong with this programwhat is
wrong with this program import java.io.*;
class Distance
{
int feet,inch;
void read()
{
System.out.println("Enter distance in feet and inches ");
feet=Integer.parseInt(ob.readLine());
inch
What is wrong with my servlet?What is
wrong with my servlet? I'd like to know which part of the code is
wrong.
My code is:
print("code sample");
import java.util.*;
import java.io.IOException;
import java.io.PrintWriter;
import
what is wrong in this programwhat is
wrong in this program import java.io.*;
class Distance
{
int feet;
int inch;
void read(int feet, int inch)
{
System.out.println("Enter distance in feet and inches ");
feet=Integer.parseInt(ob.readLine
what is wrong in this program......what is
wrong in this program...... program to implement given inheritance
import java.io.*;
class Student
{
int rno;
String name;
DataInputStream ob = new DataInputStream(System.in);
void getRoll
user log in according to their roleuser log in
according to their role i want a jsp code for different users log in to different pages
according to their role.example normal user and administrator. normal user for user page and administrator for admin page
user log in according to their roleuser log in
according to their role i want a jsp code for different users log in to different pages
according to their role.example normal user and administrator. normal user for user page and administrator for admin page
Sql aggregate function with left join wrong output
I ma getting
wrong sum
values of i.InvoiceQuantity,p.IssueQuantity column...Sql aggregate function with left join
wrong output I have three tables Stock,InwardEntry,IssueToProd. Part_no in stock is a primary key
Sql aggregate function with left join wrong output
I ma getting
wrong sum
values of i.InvoiceQuantity,p.IssueQuantity column...Sql aggregate function with left join
wrong output I have three tables Stock,InwardEntry,IssueToProd. Part_no in stock is a primary key
Sql aggregate function with left join wrong output
I ma getting
wrong sum
values of i.InvoiceQuantity,p.IssueQuantity column...Sql aggregate function with left join
wrong output I have three tables Stock,InwardEntry,IssueToProd. Part_no in stock is a primary key
Help me to write this simple java frame program and pin;with suitable labels.
Also add a button "
OK". After enter
values and
when
OK is clicked, corresponding
values to be appeared. let it appear...Help
me to write this simple java frame program I want to write