Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Yet another bump in the programming road..

 
jason candelora
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

JOptionPane.showMessageDialog(null,

"Your converted string is " + result,

"The Results",

JOptionPane.INFORMATION_MESSAGE);

}//end method

}//end class
Thanks again!!!
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 210
Ruby Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Jason -
When posting code snippets, please use the UBB tags to make the code much easier for us to read.
Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic