public static void Main (string[] args) {string strnumbers = "0123456789";//System.out.println used for judging the number ("Please enter a string:"); String string = new Scanner (system.in). Next (); Custom input string[] strings = new String[string.length ()];//Custom is String System.out.println ("Custom length = =" +strings.length);// Loop the custom string and place each character into the array for (int i = 0; i < string.length (); i++) {Strings[i] = string.substring (i, i + 1);} int length = 0;//defines the index subscript int suminteter = 0;//computes the integer boolean bool = true; string[] STRs = new String[string.length ()];//then create a new array to hold the continuous number as a sequential data, or loop all the strings for (string str:strings) {// Put the corresponding string into the Strnumbers using IndexOf method to determine whether; Returns -1int index = Strnumbers.indexof (str) If it is returned, or the IF (index = =-1) {//indicates that the current value is not a number strs[length] = str;//assigns the current value directly to the number Group length++;//index Subscript self-increment bool = true; Lock on} else {//= the current value is a number if (bool) {Strs[length] = Str;length++;suminteter++;bool = false;//Lock is closed so the lock is closed because the next character is also the number is run below E LSE Operations} else {//current and previous values are also numbers, run this step//Because the previous index has since been increased, the index must be-1, use concat to link the number to the tail of the previous value strs[length-1] = strs[Length-1].concat (str); }}}system.out.println ("Number of integers" +suminteter+ "a"); for (String str:strs) {if (str! = null) {System.out.println (str);}}}
Java to find consecutive numbers in a string as a whole and return consecutive numbers and the total number of integers