Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes Yet another bump in the programming road.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Yet another bump in the programming road.." Watch "Yet another bump in the programming road.." New topic

Yet another bump in the programming road..

jason candelora

Joined: Sep 25, 2003
Posts: 16
Can someone help me to see why the variable result is valued at 88 and not 10?
import javax.swing.*;
import java.text.*;
import java.util.StringTokenizer;
public class romanNumeral
public static void main(String[] args)

int I = 1;

int V = 5;

int X = 10;

int L = 50;

int C = 100;

int D = 500;

int M = 1000;
String input = "X";

int i = input.length();

int b = 0;

int result = 0;

while (i > 0)


char character = input.charAt(b);

result = character;
i = i - 1;

b = b + 1;

}//end while


"Your converted string is " + result,

"The Results",


}//end method

}//end class
Thanks again!!!
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
These types of problems are easily diagnosed and resolved using a debugger. Take a look at free ones: JBuilder, Eclipse, etc.
Wirianto Djunaidi
Ranch Hand

Joined: Mar 20, 2001
Posts: 210

Looking at the classname, I am guessing you are tring to convert roman number to regular number.
Your problem is a this snippet of your code:

You did not convert the character, you just assign whatever the character
value into result. I don't remember my ascii table, but I guess the character 'X' is 88 in the ascii table.
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 805
Hi, Jason -
When posting code snippets, please use the UBB tags to make the code much easier for us to read.

Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
I agree. Here's the link:
subject: Yet another bump in the programming road..
It's not a secret anymore!