简体   繁体   中英

Reading a character input in the console using the Scanner Class in Java

I am trying to read a character input at the console using the Scanner class, by creating a scanner object. I used two commands:

  1. char ch = sc.next(".").charAt(0);
  2. char ch = sc.next().charAt(0); I've tried both and both work well, but what's the difference between the two commands? What does the "." in the first command stand for?

This method Finds and returns the next complete token from this scanner. A complete token is preceded and followed by input that matches the delimiter pattern.

char ch = sc.next(".").charAt(0);

In this code it waiting to match this from this input "."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM