As shown below:
import java.util.Scanner; public class Main { public static void main(String[] args) {Scanner in = new Scanner(System.in); while(in.hasNextLine())//Judge whether there is inputting a line of data {String tmp = in.nextLine();//Read a line of data if(tmp.equals("q"))//Enter q to exit the program break;String arr[] = tmp.split("//s+");// Use regular expression to split the string "//s+" to represent multiple spaces int sum = 0; for(String a:arr)//Transfuse all strings and convert them into integer sum {sum+=Integer.parseInt(a);}System.out.println(sum);}}}The above article Java reads a line of space-separated numeric strings and finds the sum of these numbers. I hope that I can give you a reference and I hope that you will support Wulin.com more.