ok, I'm taking my first Java class and in my first week. I've searched but this is different from .Net so much that I have a headache just getting eclipse set up and how to navigate the environment.
That said, I have a program that would take me 5 minutes to do in Visual Studio that I can't figure out in Java.
Here is the code
public static void main(String[] args) {
String inputNumber;
String number1;
String number2;
String number3;
String number4;
String number5;
inputNumber = JOptionPane.showInputDialog("Enter a five digit number ");
number1 = inputNumber.substring(0,1);
number2 = inputNumber.substring(1,1);
number3 = inputNumber.substring(2,1);
number4 = inputNumber.substring(3,1);
number5 = inputNumber.substring(4,1);
JOptionPane.showMessageDialog(null, number1 + " " + number2 + " "+ number3 + " " + number4 + " "+ number5);
System.exit(0);
}
what I'm supposed to do is accept input of 5 numbers and then display them separated by five spaces. So if entered 05852 it would then display 0 5 8 5 2
I'm getting
"Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source)
at practiceArithmeticOperators.PracticeArithmeticOperators.main(PracticeArithmeticOperators.java:29)"