according to me its ok but is calculating wrong values in

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

Ads









Related Tutorials/Questions & Answers:
according to me its ok but is calculating wrong values in
according to me its ok but is calculating wrong values in   program to calculate roman numbers .....i.e roman number calculator import java.util....); System.out.println("enter the choice for calculating \n 1 for addition \n 2
How to get the correct value by calculating double values....
How to get the correct value by calculating double values....  Hello... and values like 59,142 etc here i am getting wrong output for the same duration 59 i am getting wrong cost .. Sir plz help me in this code.Thank you Sir
Advertisements
How to get the correct value by calculating double values....
How to get the correct value by calculating double values....  Hello... is integer type and values like 59,142 etc here i am getting wrong output for the same duration 59 i am getting wrong cost .. Sir plz help me in this code.Thank you Sir
ModuleNotFoundError: No module named 'know_its_ok'
ModuleNotFoundError: No module named 'know_its_ok'  Hi, My Python... 'know_its_ok' How to remove the ModuleNotFoundError: No module named 'know_its_ok' error? Thanks   Hi, In your python environment
Ple help me its very urgent
Ple 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 urgent
Please 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
Wrong parameter values while exporting data from jsp to excel
Wrong parameter values while exporting data from jsp to excel   This is a jsp report. When i export the report data to an excel, the parameter values on the html report do not match those in the downloaded spreadsheet
pls help me sir its urgent
pls 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
its very urgent please help me
its very urgent please help me  how can i retrieve all images from ms access database and display in jsp pages
servlet not working properly ...pls help me out....its really urgent
servlet not working properly ...pls help me out....its really urgent  Hi, Below is the front page of my project 1)enty.jsp </form> </body> </html> </form> </body> </html>> <
Calculating current Experience
Calculating 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
I want to update the multiple values of database depending on checkbox..? Please help me out..
I want to update the multiple values of database depending on checkbox..? Please help me out..   Hi .. I want to Update the multiple values of database using checkboxes and want to set the session for selected checkboxes
I am trying to develop a Image Sliding application but unfortunately its not working... Can any one help me in this
I am trying to develop a Image Sliding application but unfortunately its not working... Can any one help me in this  Can Anyone Help Me In This import java.awt.*; import javax.swing.*; import java.awt.event.*; class SlideShow
displaying List of records from database in a jsp using ajax, onclick it should display the results ?? its urgent can u help me
displaying List of records from database in a jsp using ajax, onclick it should display the results ?? its urgent can u help me   displaying List... ?? its urgent can u help me
Pls provide me jsp code to get values in drop down list from another table's field....
Pls provide me jsp code to get values in drop down list from another table's field....  my project has customer registration and company registration........ pls provide me code.. thanx
Java Program for Calculating Marks
Java 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 Marks
Java 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 Marks
Java 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 Marks
Java 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
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'
change color according to the database value
change color according to the database value  any one know how to get values from database ( 1 or 0 ) and according to that change the color ( red or green) of given list
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
User LogIn According to Role
User 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 line
What 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
what is wrong with this program
what 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
user log in according to their role
user 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 role
user 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
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 program
what 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
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

Ads