Home Answers Viewqa Java-Beginners according to me its ok but is calculating wrong values in

 
 


Ajeet Pratap Singh
according to me its ok but is calculating wrong values in
0 Answer(s)      a year and 4 months ago
Posted in : Java Beginners

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 Pages:
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
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
wrong year
= [NSDate date]; NSLog(@"%@", [df stringFromDate:date]); return; Its giving me wrong year..   I think u are using other calendar Check Settings... wrong year  hello I m using the following code: NSDateFormatter
reply me its urgent - Java Beginners
reply 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
Calculating the checksum of a Byte Array by using Adler32
Calculating the checksum of a Byte Array by using Adler32... the packets before accepting it. In this example we are calculating a value... we have  taken is 5, you can change it according to your own needs. Use
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
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
What's wrong with my form? - Java Beginners
What's wrong with my form?  Dear expert, I'm having trouble with my enquiry form. Hope you can tell me where my mistake lies. Thanks... += "(strName, strEmail, strContact, strEnquiry + VALUES (?,?,?,?)"; ps.executeUpdate
Text box size varying in IE 7 but ok in firefox - Java Beginners
Text box size varying in IE 7 but ok in firefox  I have problem with the size of text field which varies in IE 7 only but its fixed in Firefox( I have two text boxes one for email id and other for password both with the same text
its urgent for me - Development process
its 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
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
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
how to display data from database according to entered value in search field
how to display data from database according to entered value in search...;/html> i suppose to get this table, but it shows wrong value .i want..., so i want the data of user who have 17 as their bmi value to appear. help me
Calculating the checksum of a file/Adler32
Calculating the checksum of a file/Adler32   .... CheckedInputStream: It is a input stream that keeps the checksum. Its constructor use two...[1024];  //can change the size according to needs     while
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
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
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
Not sure whats wrong with my code HELP PLEASE?!?!
Not sure whats wrong with my code HELP PLEASE?!?!  I cant figure out what I am doing wrong in my code can anyone help me out??? Grades function computeGrade( ) { var hw, lab, midt, fin, avg; hw = parseFloat
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
what is wrong with my JSP codes for updating a form?
what is wrong with my JSP codes for updating a form?  Hi experts, I have tried to emulate a code from a textbook but it doesn't work in my program. Hope someone can advise me where I had gone wrong. Tks. I've set up my
DIFFERENT PAGES FOR DIFFERENT USERS ACCORDING TO THEIR ROLE
DIFFERENT PAGES FOR DIFFERENT USERS ACCORDING TO THEIR ROLE  I HAVE A PROBLEM IN PHP CODING PLS HELP ME PROBLEM IS THAT I WANT DIFFERENT PAGES TO VIEW FOR DIFFERENT USERS WHEN THEY LOGIN ACCORDING TO THEIR ROLE IN DATABASE
What's wrong with my pagination code in JSP?
What's wrong with my pagination code in JSP?  Dear experts, I've... whatever lines that NetBean IDE has given me error signal. The resulted page.... Hope someone can advise me how to. Thanks! print("code sample"); <
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
Calculating the checksum of a Byte Array by using CRC32
Calculating the checksum of a Byte Array by using CRC32  ... to check the packets before accepting it. In this example we are calculating a value... of type byte, the array size we have  taken is 5, you can change it according
GUI Interface .Reply me with in hour..Its Urgent - Java Beginners
GUI Interface .Reply me with in hour..Its Urgent  Hi ... Now i am doing project for Voting finger print Authentication .. Can any pls assit me.. I... Existing project... Help me
Plz reply me sir Its urgent - JSP-Servlet
Plz 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
hi i m new to hibernate..plzzzzzzzzzzzzzz help me.... - Hibernate
...... plzzzzzzzzzzzzzzz help me whats the problem... its showing me //************Error... change my query ... now its showing me this error... plz help me..... MY PRG...hi i m new to hibernate..plzzzzzzzzzzzzzz help me....  hi friends i m
do the combinations in java, pls help me its urhent - Development process
do the combinations in java, pls help me its urhent  import java.util.*; interface Expression { public void interpret(ArrayList exp); } class... one help me: action when condition1 and condition3 action when condition1
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>> <
Values to listbox
Values to listbox  I have two textboxes by the name street and city.I have an add button and a name listbox. When I enter street and city and press.... Plz help me out with the coding in java script...plz
help me...
help me...  there is the picture given - cat - dog - rabbit - mouse a. create a class name b. create its attributes (at least 3 attributes) : species, size, leg c. create its methods ( at least 3 methods) : walk, eat, sleep
Retrive Values
Retrive Values  I want to retrive the values between the td by the id using the javascript.So please help me... html form like this <TABLE width="100%" bgColor=""> <TR> <TD ID="td1">Cell 1</TD>
How to declare a Combobox without using a string in its declaration?
How to declare a Combobox without using a string in its declaration?  ... the values later? For example JComboBox x= new JComboBox(); ... String s={"Alpha... the examples and tutorials so far i haven't found any which tells me how to do
help me..
help me..  Design and write a class named Person and its two subclasses named Student and Employee. Make Lecturer and Admin subclasses of Employee. A person has a name, address, phone number and email address. A student has
On click Checkbox values displayed in text box
On click Checkbox values displayed in text box  Hi sir, If i onclick the checkbox values should be displayed in text box, the following code is working properly in Internet Explorer browser but its not working in Google chrome
On click Checkbox values displayed in text box
On click Checkbox values displayed in text box  Hi sir, If i onclick the checkbox values should be displayed in text box, the following code is working properly in Internet Explorer browser but its not working in Google chrome
Populate listbox according to selection value from another selectbox
Populate listbox according to selection value from another selectbox  hi... I am developing my webproject in which i have 3 campus and each campus... me.... my code............... <%@ page language="java" %> <%@ page
i am getting multiple values in listbox
i am getting multiple values in listbox   hi sir, i am using... getting its working fine, but in main query also i am getting multiple name but i want only distinct names pls help me