So I'm trying to make a converter from roman numerals to integers. What I have so far is this:
public int toNumber(String n){
int number = 0;
int first = 1;
int last = 0;
String substring = n.substring (last, first);
while(substring.equals("I")){
number = number+1;
last = last +1;
first=first +1;
}
while(substring.equals("V")){
number = number+5;
last = last +1;
first=first +1;
}
return number;
}
Obviously I only have I and V in right now, but when I make a tester class to try this out, it returns nothing and keeps letting me put in in a new line.
For the record, here is my tester class
import java.util.Scanner;
public class Tester{
public static void main (String[] args){
RomanNumeralConverter quantity = new RomanNumeralConverter();
Scanner user_input = new Scanner(System.in);
//this is for roman to number
System.out.println("input roman numeral");
String j = user_input.nextLine();
int g = quantity.toNumber(j);
System.out.println(g);
}
}
I'm almost entirely certain that it's a logic problem, but I have no idea what and I feel like I've tried everything I can think of