-5

I need to ask for coordinates, so I would only like to read a SINGLE character(from console). How is it done? I can't find anything in the documentation/tutorials. Thanks in advance!

silent947
  • 1
  • 1
  • 3
    The first search engine result led me [here](http://stackoverflow.com/questions/13942701/take-a-char-input-from-the-scanner) – Reimeus Apr 13 '15 at 20:30

2 Answers2

1

You can try using this code:

Scanner in = new Scanner(System.in);

char firstChar = in.nextLine().charAt(0);

for a String, and you can use this code for ints:

Scanner in = new Scanner(System.in);

int firstNumber = in.nextInt();
Connor Wright
  • 100
  • 13
0

Coordinates are actually numbers (believe it or not) so you would need to read 2 int variables, x and y axis. (Eg. X23 Y37)

In order to do so u need to import Java.util.scanner at the beginning of your program.

Import Java.util.scanner

Wherever you want to ask for the coordinates do this

Scanner scan = new Scanner(System.in);
System.out.print("input x: ");
int x = scan.nextInt();

You might wanna define x as a global variable for other part of your code to use it but that's all u really need. Now just do the same as the y and u got ur coodinates

Mazino
  • 542
  • 5
  • 21