I'm trying to format the String sequence "a b c" where a b and c are all whole number integers.I need to add a b and c to 3 separate arrays.Here is what I have. When prompted for the str, the error of NumberFormatException keeps showing up.
I have tried changing up some variables and their declarations and looking at other explanations online.
import java.util.*;
import javax.swing.*;
public static void main(String[] args){
Scanner s = new Scanner(System.in);
System.out.println("How Many times do you want to loop it?"); //Scanner takes in input
int loop = s.nextInt();
//if someone can help me format this better or have a 3d array that would be helpful.
ArrayList<Integer> a1 = new ArrayList<Integer>(); //3 arrays
ArrayList<Integer> b1 = new ArrayList<Integer>();
ArrayList<Integer> c1 = new ArrayList<Integer>();
String a = ""; //Int #1
String b = ""; //Int #2
String c = ""; //Int #3
String strSpc = " "; //String Spaces to compare with actual String
int x = 0;
String str = " ";
//Start of the error
for(int i=0; i<loop;i++) {
str = JOptionPane.showInputDialog(i+1 + ": ");
//checks format
while(str.charAt(x) !=(strSpc.charAt(0))){
a = a + str.charAt(x);
x++;
}
int a2 = Integer.parseInt(a);
a1.add(a2);
while(str.charAt(x+1) !=(strSpc.charAt(0))){
b = b+str.charAt(x);
x++;
}
int b2 = Integer.parseInt(b);
b1.add(b2);
while(str.charAt(x+1) !=(strSpc.charAt(0))){
c = c+str.charAt(x);
x++;
}
int c2 = Integer.parseInt(c);
c1.add(c2);
System.out.print('\n');
}
}