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!
Asked
Active
Viewed 116 times
2 Answers
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
- 110
- 1
- 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
- 552
- 6
- 27