As I run this program, when the string "How are you today?" is inputted into the console, instead of being able to type in the Key Matrix into the console after that, the code seems to skip straight to test.process(); which gives me these errors:
Exception in thread "main" java.lang.NumberFormatException: For input string: " are you today?"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:569)
at java.lang.Integer.parseInt(Integer.java:615)
at EncoderAdd.stringtoKey(EncoderAdd.java:24)
at EncoderAdd.process(EncoderAdd.java:93)
at Runner.main(Runner.java:19)
The methods that the errors point to are here:
System.out.println("Type message to be encoded here:");
String encode = in.next();
if (encode.length() > 0){
System.out.println("Type key matrix here (Like: k1, k2, k3, k4):");
String kmatrix = in.nextLine();
System.out.println("");
EncoderAdd test = new EncoderAdd(encode, kmatrix);
test.process();
}
public void stringtoKey(){
String[] temp = mat.split(",");
for (int i = 0; i < temp.length; i++){
keyMat[i] = Integer.parseInt(temp[i]);
}
}
public void process(){
stringtoKey();
stringtoInt();
addkeytoInt();
intArrtoFinal();
}
How do I fix the errors that are occurring? Thank you!