In Java's Scanner class, why does the syntax nextChar() not exist, and is there a command would do something similar with out using the String variable?
Two solutions:
toCharArray(): this will return a char[] over which you can use a foreach loop;.charAt().Java's Scanner class operates on tokens, complete units of output. This is usually complete words, lines of text, numbers (integers, doubles, floats, etc). If you want to read individual characters, you should use BufferedReader in a construct like this
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
Replacing System.in with whatever input you're using for Scanner. Then use char c = (char)in.read() to read the next character from the input.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With