@OP: should you finally read this:
- post your code
- before posting code, read http://forum.java.sun.com/help.jspa?sec=formatting
- tell us what you think it should do
- tell us what it does instead
We can help you solving some problems, but we're not going to create your program for you.
import java.io.*;
class MidtermProject
{
public static int toArabic (String x)
{
int arabica=0;
char chars;
for (int y=0; y<=(x.length()-1); y++)
{
chars=x.charAt(y);
switch (chars)
{
case 'C':
if (x.charAt(y+1)=='M')
{
arabica+=900;
y++;
}
else if (x.charAt(y+1)=='D')
{
arabica+=400;
y++;
}
else
{
arabica+=100;
}
break;
case 'X':
if (x.charAt(y+1)=='C')
{
arabica+=90;
y++;
}
else if (x.charAt(y+1)=='L')
{
arabica+=40;
y++;
}
else
{
arabica+=10;
}
break;
case 'I':
if (x.charAt(y+1)=='X')
{
arabica+=9;
y++;
}
else if (x.charAt(y+1)=='V')
{
arabica+=4;
y++;
}
else if (x.charAt (y+1)== 'I')
{
arabica+=2;
y++;
}
else
{
arabica++;
}
break;
case 'M':
arabica+=1000;
break;
case 'D':
arabica+=500;
break;
case 'L':
arabica+=50;
break;
case 'V':
if (x.charAt(y+1)== 'I')
{
arabica+=6;
y++;
}
else
arabica+=5;
break;
}
}
return(arabica);
}
//main program
public static void main (String [] args)
{
String r_input, ro;
int ans1;
DataInput keyboard=new DataInputStream (System.in);
try
{
System.out.print("Enter a Roman numeral: ");
r_input=keyboard.readLine();
ro=r_input.toUpperCase();
ans1=toArabic(ro);
System.out.println("The Arabic number is: "+ans1);
}
catch (Exception e)
{
System.out.print ("Wrong inPut!");
}
}
}
//this is my program...and there are some roman numrals that are nt functioning....
> @OP: should you finally read this:
>
> - post your code
> - before posting code, read
> http://forum.java.sun.com/help.jspa?sec=formatting
> - tell us what you think it should do
> - tell us what it does instead
>
> We can help you solving some problems, but we're not
> going to create your program for you.
> what is a stack trace? im so sorry im a first timer
> in java...sowi for my questions
} catch(SomeException ex) {
ex.printStackTrace();
}
This will make the exception give you an error message and tell you where in your program the problem occured. Makes it easier to find the cause.