How To Convert Integer To Roman Numerals

Aug 20, 2014

I don't need the code , I just want to try on my own ....

View Replies


ADVERTISEMENT

Java Program To Convert Integer To Roman Numbers And Vice Versa?

Aug 20, 2014

java program to convert integer to Roman numbers and vice versa?

View Replies View Related

Program To Add 2 Roman Numerals Together And Return The Results

Feb 26, 2014

Writing an program to add any 2 given Roman numerals together and return the results.

[I don't want to convert Roman numbers to decimal numbers & then add together, then convert in to Roman numerials ]

Is there any direct way to add roman numerials?

For example: I + I = II
III + I = IV

View Replies View Related

How To Write Conversion Method From Roman Numerals To Arabic

Nov 8, 2014

I am a student taking a Java programming class. My assignment is to write a program that converts a roman numeral input as entered by a user and converting it to it's integer value (arabic number). These are the methods that I must have in it:

1. Write a method that takes input from the user and passes it to a conversion method.
2. Write a method that yields the numeric value of each of the letters (conversion method).
3. Write a method that outputs the number the user entered and the converted number.
4. Write a main method to test the 3 methods.

I have written the first method, at least I think. Here is what I did there:

public static String romanInput(String number) {
Scanner numberInput = new Scanner (System.in);
System.out.print("Enter a roman numeral: ");
String userInput = numberInput.next();
return userInput;
}

I returned the userInput and I think that is passing it to the conversion method? Now I am working on this conversion method and to be honest I don't know where to begin. I am told how to convert a string in my assignment by the professor. I am told:

- Look at the first two characters. If the first has a larger value than the second, then simply convert the first.
- Call the conversion method again for the substring starting with the second character.
-Add both values. If the first one has a smaller value than the second, compute the difference and add to it the conversion of the tail.

I am also told to use a single-dimensional array. But, I don't know what I am to use a single dimensional array for? So this is what I wrote so far for this method:

public static int numberConversion(int number) {

int romanConv = 0;
char[] romanNum = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
char[] arabicNum = {1, 5, 10, 50, 100, 500, 1000};
romanNum = arabicNum;
}

I have written a character array for the roman numerals, and then one for arabic numerals, then I set them equal to each other. I also declared an integer variable set to 0 because I think that is what I will be returning at the end of the method. Now I don't know where to start for the conversion algorithm here. I know this is what I have to do, but I don't know how to do it:

1. Add the numbers together if they are in decreasing value or are equal in value. For example: VI is read as 5 + 1 = 6 XVI is read as 10 + 5 + 1 = 16 XXXVIII is 10 + 10 + 10 + 5 + 1 + 1 + 1 = 38
2. Use subtraction if a number is less than the number that follows it. For example, I is less than V, so when I is in front of V, you subtract its value.
3. For example: IV is 5 1 = 4 IX is 10 1 = 9 XL is 50 10 = 40 MCM is 1,000 + (1,000 - 100) = 1,900

I can't use hashtables or enums because I haven't learned about that yet. I have a feeling I need to use a for loop. I know I haven't done any of the actual programming work but I don't know how to begin writing this conversion method.

View Replies View Related

Convert Roman To Ordinary Conversion Without Using Any Predefined Methods

Feb 25, 2015

convert roman to ordinary conversion without using any predefine methods,where we are giving input thru command prompt

View Replies View Related

Allow User To Enter Roman Numeral And Then Outputs Integer Number Value - While Loop

Feb 7, 2015

Write a program called RomanNumeralHelper that allows a user to enter a roman numeral and then outputs the integer number value. Use a Scanner to accept command line input from the user and continually ask for a roman numeral until the user enters Q (or q) to stop. Your solution should NOT use a switch statement.

Here is sample input / output:

Enter a roman numeral [Q | q to quit]: III
>> 3
Enter a roman numeral [Q | q to quit]: IV
>> 4
Enter a roman numeral [Q | q to quit]: V
>> 5
Enter a roman numeral [Q | q to quit]: Q
Good Bye!

This is what I have so far in my code, but I cant get what the user inputs when I want it to output the number.

import java.util.Scanner;
public class RomanNumber4
{
public static void main(String[] args) {
// obtain input from command window
Scanner input = new Scanner(System.in);
 
[Code] ....

View Replies View Related

Convert String To Integer

May 21, 2014

I have to make a programm where the user gives you the bank sorting code and the account number and you give him the IBAN. That was so far no problem and I was done within minutes except of one thing that I simply can't figure out even though im trying since weeks. At some point I have to convert a string to integer. My research told me its with parseInt() and I dont get a syntax error when I compile my programm (using BlueJ). But when executing the programm stops and gives me some weird bug message. Here is code and bug message:

Java Code:

public class IBAN {
public IBAN(String Bankleitzahl, String Kontonummer) {
Bankleitzahl=Bankleitzahl.replace(" ",""); // Die Leerzeichen werden entfernt
int Anzahl=Bankleitzahl.length(); // Auf der Variabel Anzahl wird die Anzahl der Zeichen von der Bankleitzahl gespeichert

[Code] .....

View Replies View Related

How To Convert Integer To That Many Asterisks

Jan 22, 2015

int a = 5;

//how do I convert a to 5 asterisks '*'?

When I do System.out.println(a); I want there to be 5 asterisks '*****'

View Replies View Related

JSP :: How To Convert String Into Integer In JSTL

Feb 17, 2015

I am having problem in converting JSTL variable into integer type in JSP (not using Spring). I am looking to do something like below:

<c:set var="total_amt">${list.totalAmount}</c:set>
<c:when test="${new Integer(total_amt) > 500}">

View Replies View Related

How To Convert Formatted String To Integer

Feb 15, 2014

If I use the class DecimalFormat to format long number, how can I convert it back to integer?

DecimalFormat longFormat = new DecimalFormat("#,###");
long testLong=11000;
String strLong=longFormat.format(testLong);
System.out.println("NUM : " + strLong);
//Assume that at this point I don't have
//testLong, I have only the strLong value...
long newLong=Long.parseLong(strLong) * 2; 
//java.lang.NumberFormatException: For input string: "11,000

View Replies View Related

Convert Integer List To Int Array?

Sep 24, 2008

is there a way, to convert a List of Integers to Array of ints (not integer). Something like List<Integer> to int []?

View Replies View Related

Convert Currency Instance To Integer

Jul 26, 2014

I am working with a JFormattedTextField. After adding the text of the FormattedTextField to an LinkedList i want to read it out and sum it up. So I have a problem to convert the String to and integer...

Example:

23.00 - to 23.00
+ 11.00 - to 11.00
--> 34.00

I have tried it with splitting the string but it didn't work. How to do it?

View Replies View Related

Convert Integer To Letter Grades

Jan 31, 2014

/*This program will convert integer grades to letter grades and say how many A's, B's, C's, D's , F's do we have

public class DSlab3 {
private char LetterGrades;
private int IntegerGrades;
//default constructor
public DSlab3() {
LetterGrades =' ';
IntegerGrades = 0;

[Code] .....

View Replies View Related

Convert Hexadecimal To Decimal WITHOUT Using Integer ParseInt Method

Mar 12, 2014

So I have to write a java program that converts hexadecimals to decimals without using the whole "integer.parseInt(AB1, 16)" method. I tried looking up how to do this but every forum/site I went to used this same method.

View Replies View Related

Using Static Method To Convert A String To Integer Object - Compiler Error

Mar 1, 2014

I am using a static method to convert a string to an Integer object. Next using a instance method to convert Integer object to an int.

Compiler is giving me two "cannot find symbol" errors:

One pointing to the dot operator between "Integer.valueOf(s)"

The other pointing to the dot operator between "obj.intValue()"

I have latest JDK installed: jdk-7u51-windows-x64.exe

Looks like JCL installed correctly with rt.jar file located in "lib" directory under "Program Files"

Following is source code:

Java Code:

public class StringToInt
{
public static void main (String args [])
{
String s = "125";
Integer obj = Integer.valueOf(s);
int i = obj.intValue();
i += 10;
System.out.println(i);
}
} mh_sh_highlight_all('java');

View Replies View Related

Program To Convert A Base 10 Integer To Any Base 2 - 16

May 5, 2013

I am writing a program to convert a base 10 integer to any base 2-16. Here are the terms:"The method is to convert the decimal value the user selected into whatever base the user selected and print the converted value one place value at a time by using an index into an array of characters 0-9 amd A-F that is initialized to contain those characters.In the method you will find the largest place value (i.e. power of the base) that will divide into the decimal number.

Then you can set up a loop that will operate from that power down to and including the 0th power to determine how many times each place value goes into the decimal number. Using the loop counter, index into the character array to print the character that corresponds to the quotient number and then subtract the product of the place value and the quotient from the decimal number. With the power (loop index) decreased, repeat until you finish the 0th place value. Here's what I have so far:

import java.io.*;
import java.util.Scanner;
public class ConvertIt
{//start program
public static void main(String[] args)
{//start main
Scanner input = new Scanner(System.in);
System.out.println("Enter a positive integer from 0 to 10000.");
int number = input.nextInt();

[code]...

View Replies View Related

Roman To Arabic Numbers Converter

Oct 5, 2014

I'm trying to do a program to convert roman numbers to arabic numbers. My problem is that I don't have the right to use Methods and Arrays. Only loops and if/else.

View Replies View Related

Roman To Arabic Converter Says Everything Equals 1

Mar 25, 2015

Im working on a roman numeral to arabic converter and all I had to do was fill out the conversion method romanToDecimal. But for some reason no matter what number I enter It always says my number is equal to one.

//Quiz 1 EC
import java.util.*;
class Roman {
private String romanNum;
private int decimalNum;
public Roman(){
romanNum = "I";
decimalNum = 1;

[code]....

View Replies View Related

Roman Numeral Conversion To Decimals

Jul 29, 2014

I have made a program that is supposed to convert roman numerals to decimals. It is NOT supposed to convert decimals to roman numerals. The only problem it seems there is with the program is that it only adds and does NOT subtract. This causes some roman numeral conversions to be flawed. What can I try to fix this. Keep in mind that the reason some methods exist is because the directions for the code say that I have to make it this way.

Instructions:

Write a program that converts a number entered in Roman numerals to decimal. Your program should consist of a class called Roman. An object of type Roman should be able to do the following:

1) Store the number as a Roman numeral.
2) Convert and store the number into decimal.
3) Print the number as a Roman numeral or decimal number as requested by the user. (Be sure to over-ride the toString function).
4) Your class must contain the method romanToDecimal to convert a Roman numeral into its equivalent decimal number.
5) Test your program using the following Roman numerals: MCXIV, CCCLIX, and MDCLXVI.

This is what I have so far. It compiles and there are no errors, but it does not subtract I from X, or I from V and so on. For example,CMXLVII should be 947, but the program outputs 1067.

import javax.swing.*;
import java.util.*;
public class Roman{
private String roman;
private int decimal;
public int romanToDecimal(String s)

[Code] .....

View Replies View Related

Arabic To Roman Numeral Converter

Sep 12, 2014

I got part of this converter built and running fine but now it's getting weird. Specifically I am getting to the part where I have to count above ten which means things like attaching Vs to Is and Xs and suchlike.

I know I have to use an .append someplace, I am just not certain how to go about it. I've been playing with it some, but this is honestly the biggest thing I've built so far that actually *ran* so I'm afraid to poke too many holes in it... where do I start? It's not like I can invent another return string and concatenate them. R is what I've got.

package hello;
public class RomansatHomans {
public static void main(String[] args) {
// input fed on this line loops through toRo and comes back as a String
// R
String R = toRo(23);
// int D = froRo("x");

[Code] ......

View Replies View Related

Ask User To Enter Number From 1 To 10 And Program Will Display Roman Numeral

Feb 6, 2014

I am trying to write a program that asks the user to enter a number from 1 through 10 and then the program will display the roman numeral for that number.

I am also adding a error message in which i haven't yet because im still trying to figure out how to the program will do the roman numeral.'

I have used the if and else if. but when i input a number it just repeats the number back to me.

The program cimpiles but it doesn't do what i want. here is what i have so far. how can i get the program to display the roman numeral after the number is entered.

import javax.swing.JOptionPane;
public class Romannumeral
{
public static void main(String[] args)
{
double number;
 
[Code] .....

View Replies View Related

Can't Seem To Get Value For Integer 1 And Integer 2 To Pass With SetValue Method

Aug 10, 2014

public class MyInteger {
private int value;
public MyInteger(int number){
value = number;
System.out.println("Constructor created with value of " + value);

[code]....

I can't seem to get the value for integer1 and integer2 to pass with the setValue method. I get a runtime error stating the I need to have an int value for these two integers.

View Replies View Related

Cannot Convert Int To Boolean

Dec 11, 2014

I am making a program which accepts two user inputs one being a letter either upper or lower case and the other being a number. the out come should be some thing like this:

G
GG
GGG
GGGG
GGGGG

This is assuming the user inputted 'G' and '5'.

here is the code i have so far:

package week10;
import java.util.Scanner;
public class integer {
public static void main(String args[]) {
Scanner user_input = new Scanner( System.in );

[Code] ....

The problem i am having is that i cant get the number that is inputted to be accepted as a variable to be used for the program.

View Replies View Related

Convert Int To String

Nov 17, 2014

How can i convert int to string ? The error I get is count cannot be resolved.

System.out.print("How many days?: ");
numberOfDays = keyboard.nextInt();
for(int count = ':';count <=memberCount; count++ )
System.out.print("What is band member # " + "'s name?");
memberName = keyboard.nextLine();
System.out.print("What is"+ memberName+"'s instrument?");
instrument = keyboard.nextLine();
members +=(count.toString() +":" + memberName +" -" + instrument + "" );

View Replies View Related

Convert To Lambda

Feb 13, 2015

I am learning about Lambdas and am having a little difficulty in a conversion. I need to introduce a List into which the array supplied by the values method of the Field class is copied, using the asList method of the class Arrays. Then I need to convert the for loop with a forEach internal loop using a lambda expression as its parameter. The body of the lambda expression will be the code that is the present body of the for loop. I believe I have the List syntax correct ( List<String> list = Arrays.asList(data); ), but I am having a hard time on figuring out what to do with the for loop, or even where to start with it.

public AreaData(String... data) {
List<String> list = Arrays.asList(data);
/* Assert to check that the data is of the expected number of items. */
assert data.length == Field.values().length : "Incorrect number of fields";
for( Field field : Field.values() )

[Code] .....

View Replies View Related

How To Convert String Into Int

Apr 16, 2014

I created a word object representing a specified string under my public class word method such as

Word w = new Word("Blue");

now I am required to return a hashcode for this word, which is an integer based on the words instance data under the method called

public Word(String w);
{
}

I am not sure how to convert the string into an int so I would be able to return a hashcode.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved