V
vamp4l
basically, its a program that displays an input window and the user
enters numbers(i.e. 21 3 45 2) on the line as a string and im trying to
parse that string and pass each integer to a vector...heres the method
im trying to use...
String numbers = JOptionPane.showInputDialog(null,"Enter the
integers", "Integers", JOptionPane.PLAIN_MESSAGE);
String n[] = new String[numbers.length()];
n[0] = numbers.substring(0, numbers.indexOf(' ',0));
int len = n[0].length();
for(int j = 1; j < (numbers.length()-j); j++)
{
n[j] = numbers.substring(len+j, numbers.indexOf(' ',len+j));
vect.add(Integer.parseInt(n[j]));
len += n[j].length();
}
Ive spent hours trying to manipulate this some way to work correctly ,
it works for every integer but the very last one, where I always get a
string index out of bounds exception for the line
n[j] = numbers.substring(len+j, numbers.indexOf(' ',len+j));
any suggestions? thanks!
enters numbers(i.e. 21 3 45 2) on the line as a string and im trying to
parse that string and pass each integer to a vector...heres the method
im trying to use...
String numbers = JOptionPane.showInputDialog(null,"Enter the
integers", "Integers", JOptionPane.PLAIN_MESSAGE);
String n[] = new String[numbers.length()];
n[0] = numbers.substring(0, numbers.indexOf(' ',0));
int len = n[0].length();
for(int j = 1; j < (numbers.length()-j); j++)
{
n[j] = numbers.substring(len+j, numbers.indexOf(' ',len+j));
vect.add(Integer.parseInt(n[j]));
len += n[j].length();
}
Ive spent hours trying to manipulate this some way to work correctly ,
it works for every integer but the very last one, where I always get a
string index out of bounds exception for the line
n[j] = numbers.substring(len+j, numbers.indexOf(' ',len+j));
any suggestions? thanks!