12-01 line breaks caused by nextline() in Java scanner class
•
Java
分析理解:Scanner sc = new Scanner(system.in);
Hasnextint() and nextint() methods of the scanner class
import java. util. Scanner; < span style="color: #008000;">/*< span style="color: #008000;"> Two common methods: public int nextint(): get a value of type int public string nextline(): there is a problem getting a value of type string: < span style = "color: #ff0000;" > Get a value first. There will be a problem when getting a string. Main reason: it's the problem of line feed symbol. How to solve it< span style="color: #ff0000;"> A: After obtaining a value, create a new keyboard entry object to obtain the string. B: Get all the data according to the string first, and then what you want, you will convert it accordingly< span style="color: #008000;">*/ < span style="color: #0000ff;"> public class ScannerDemo { public static void main(String[] args) { //< span style="color: #008000;"> Create object scanner SC = < span style = "color: #0000ff;" > new Scanner(system.in); get < / a > two int type values
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码