Method for inputting multiple integers from keyboard in Java

Example: sum of sequences

Enter two integers n and m respectively, separated by a space in the middle. N is the first item of the sequence, and the following items are the open root sign of the previous item. Find the sum of the first m items.

The first way to input and read from the keyboard: sc.hasnextint() function and sc.nextint() function

Hasnextint() determines whether the current input is an integer

The second method: sc.trim() function and sc.split() function

Sc.trim() removes the spaces at the beginning and end of the string

Sc.split() splits a string according to the specified character (string) or regular, and the result is returned in the form of string array

The above method of inputting multiple integers from the keyboard in Java is all the content shared by Xiaobian. I hope it can give you a reference and support more programming tips.

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
分享
二维码
< <上一篇
下一篇>>