Share on Google+

atoa
converting From Hexadecimal to Decimal System
2 Answer(s)      6 years and 9 months ago
Posted in : Java Interview Questions
Write a program in Java user is required to enter a number system XVI and turn it into the decimal system, using
StringBuffer

Ads

View Answers

July 12, 2010 at 2:33 PM

July 12, 2010 at 3:41 PM

Hi Friend,

Try the following code:

import java.util.*;
public class RomanToDecimal {
public static void main(String args[]) {
int decimal=0;
Scanner input=new Scanner(System.in);
System.out.println("Enter a Roman Number: ");
String roman = input.next();
String romanNumeral = roman.toUpperCase();
int x = 0;
do{
char convertToDecimal = roman.charAt(x);
switch(convertToDecimal){
case 'M':
decimal += 1000;
break;

case 'D':
decimal += 500;
break;

case 'C':
decimal += 100;
break;

case 'L':
decimal += 50;
break;

case 'X':
decimal += 10;
break;

case 'V':
decimal += 5;
break;

case 'I':
decimal += 1;
break;
}
x++;
}while(x<romanNumeral.length());
System.out.println("Decimal Number is: " + decimal);
}
}

Thanks

Related Tutorials/Questions & Answers:
converting From Hexadecimal to Decimal System - Java Interview Questions
converting From Hexadecimal to Decimal System  Write a program in Java user is required to enter a number system XVI and turn it into the decimal system, using StringBuffer  Check this link. http://www.roseindia.net
conversion from decimal to hexadecimal and vice versa
conversion from decimal to hexadecimal and vice versa  can i get the code for converting decimal to hexadecimal   Here is a code that converts decimal to hexadecimal. import java.io.*; public class
Advertisements
decimal to hexadecimal
decimal to hexadecimal  using array in java convert decimal to hexadecimal.   Hi, Please see the example Convert Decimal to Hexadecimal. Thanks
Convert Hexadecimal to Decimal
Convert Hexadecimal to Decimal     ... a hexadecimal number into decimal. Code Description: This program takes a hexadecimal...: hexadecimal and 16. It converts a hexadecimal number into a decimal number.
Convert Decimal to Hexadecimal
Convert Decimal to Hexadecimal     ... into hexadecimal. The java.lang package provides the functionality to convert a decimal... a decimal number at console and converts it  into the hexadecimal format using
converting decimal to base 32
converting decimal to base 32  procedure for converting decimal to base 32   CREATE PROCEDURE RTCONVERSION ( @valueToConvert int, @convertedValue varchar(20) out ) AS declare @counter int; declare @num int; declare @x
I converting binary to decimal and vice versa
I converting binary to decimal and vice versa  can i ask for the codes in converting binary to decimal and decimal to binary to be run in one program with repeat.. pls. help me! i badly need the codes by monday!! pls
how to convert all the pixel value to hexadecimal and from hexadecimal to binary in vb.net
how to convert all the pixel value to hexadecimal and from hexadecimal... is not available so that i selected as java.first i need to store the pixels in 2d array .from that i need to convert all the pixel values into hexadecimal how it can be done
losing precision converting from java BigDecimal to double
losing precision converting from java BigDecimal to double  losing precision converting from java BigDecimal to double
Convert Binary to Hexadecimal
Convert Binary to Hexadecimal     ... into hexadecimal.  The java.lang package provides the functionality to convert the binary data into hexadecimal.  Description of the program: This program takes
hexadecimal conversion java compilation - UML
hexadecimal conversion java compilation  write a simple program (in any language of your choice) that accepts a program of 12 binary digits) and converts them to both decimal and hexadecimal as outputs  Hi Friend
Hexadecimal numbers multiplication
Hexadecimal numbers multiplication  Sir, I have to multiply 128 bit hexadecimal numbers. Do u have any logic for this?? The numbers are like ab7564fa342b5412c34d9e67ab341b58
SQL Decimal
an example from 'SQL Decimal'. To understand and grasp the example we create... SQL Decimal       SQL Decimal is used to specify the values in decimal datatype. The Decimal datatype
Convert integer type data into binary, octal and hexadecimal
Convert integer type data into binary, octal and hexadecimal... will learn how to convert an integer type data into binary, octal and hexadecimal. The  java.lang package provides the facility for converting the data integer
convert to decimal
convert to decimal  f42a4 convert to decimal by using java
Convert Hexadecimal number into Integer
to convert hexadecimal data into integer. The java.lang package provides the functionally to convert the hexadecimal data into an integer type data.  Code... (using the keyboard) and converts the hexadecimal data into an integer type data
Convert Hexadecimal into Binary and Long
Description: This program helps you in converting the hexadecimal data... Convert Hexadecimal into Binary and Long   ... the hexadecimal data into the binary and long format. The java.lang package provides
Getting and sending data to and from mobile and the system
Getting and sending data to and from mobile and the system  Hi, For getting and sending data to mobile from system.make system is a server.From mobile send a request to the server and get response.Then process the response
swing program for decimal to binary
swing program for decimal to binary  swing program for decimal to binary
Decimal Format Issue Java
Decimal Format Issue Java  Decimal Format Issue Java
Convert Byte to Hexadecimal
Convert Byte to Hexadecimal     ... into a hexadecimal number. The package java.lang provides the functionality for this conversion. Code Description: This program takes a byte number from console
temperature converting
charts showing: The Fahrenheit equivalents of all Celsius temperatures from 0... Fahrenheit temperatures from 32 to 212 degrees in 10 degree intervals Both columns in each chart should be printed to one decimal place Print the charts
decimal to base 36
decimal to base 36  procedure for converting decimal to base 36   CREATE PROCEDURE RTCONVERSION ( @valueToConvert int, @convertedValue varchar(20) out ) AS declare @counter int; declare @num int; declare @x int
converting field to text sql
converting field to text sql  I wanted to convert the field to TEXT in SQL.. is it possible?   SQL - Converting the field to TEXT works SELECT CONVERT(TEXT,fld_name) FROM TABLE_NAME   SQL - Converting
Round the Decimal values
Round the Decimal values  How to round the decimal value with out using Math.round() Example:round the 2.7 as a 3.0 round the 2.4 as a 2.0
System
System  What is System in System.out.println() method? Is it a Class or a Package
Converting ISO8601-compliant String to java.util.Date
Converting ISO8601-compliant String to java.util.Date  Converting ISO8601-compliant String to java.util.Date
Convert Decimal to Integer
in converting a decimal type data into an integer. The parseInt() method gets... Convert Decimal to Integer       In this section, you will learn to convert  a decimal number
BINARY TO DECIMAL - Java Beginners
TO DECIMAL  Hi friend, Program to convert Binary To Decimal : import... = sc.next (); int bttm = 1; int decimal = 0; for (int i = str.length() -1; i >= 0; i--) { decimal = decimal + (bttm*Integer.parseInt
Converting a NSString into NSDate
Converting a NSString into NSDate  hello. How can I create a NSDate object out of it and then get different components like day, month, date, year from it. I have date string: Tuesday, October 19, 2010
Mysql Decimal Datatype
Mysql Decimal Datatype       Mysql Decimal Datatype is used to specify the numeric values. Understand with Example The Tutorial give you an example from 'Mysql Decimal Datatype
Tutorials

Ads

Advertisement null

Ads