0

Hii there can I write Scanner scn = new Scanner(System. In) ;char ch=scn.nextChar();

I mean does scanner class support character input by its next method ()

18th Jan 2017, 2:56 PM
Suryanarayan Behera
Suryanarayan Behera - avatar
1 Answer
+ 1
There is no method such as nextChar in java. you could use Scn.next() function to read the input whether it is a single character or a string. ( where Scn is the name that you gave your Scanner ) However, if you want to consume strictly a single character, you could also use the following : char ch = Scn.next().charAt(0); to take the first char char ch = Scn.next(".").charAt(0); for a single character string. Basically, charAt(x) function returns the xth character of the string. Hope this helps
18th Jan 2017, 5:32 PM
Snehith Haridas
Snehith Haridas - avatar