I'm attempting to capture integers from a user input using Scanner. These integers represent coordinates and a radius between 0 and 1000. It's a circle on a 2D plane.
What I have to do is to somehow capture these integers separately from one line. So, for example, the user inputs
5 100 20
Therefore, the x-coordinate is 5, the y-coordinate is 100, and the radius is 20.
The user must input all of these values on the same line, and I have to somehow capture the values from the program into three different variables.
So, I tried using this:
Scanner input = new Scanner(System.in);
String coordAndRadius = input.nextLine();
int x = coordAndRadius.charAt(0); // x-coordinate of ship
int y = coordAndRadius.charAt(2); // y-coordinate of ship
int r = coordAndRadius.charAt(4); // radius of ship
for one-digit characters, as a test. Didn't turn out so well.
Any suggestions?