This time is an enhanced version of whether the last character detection is all digital.
You are welcome to point out the shortcomings of friends or the great God.
Packagecom.hw.h817;ImportJava.util.Scanner; Public classCheck {public static void main (string[] args){Scanner s=NewScanner (system.in); //define the pre and STR outside, if the definition in the loop goes wrongString[] both =NewString[6]; String Pre; int[] str =New int[6]; intCount = 0;//used to exit a loop while(true) {System.out.println ("Please enter 6 numbers in turn"); Count= 0;//if the input character is not a number, it is counted back from if for(inti=0;i<6;i++) {Pre= S.next ();//Receive String if(! (Pre.matches ("\\d+"))) {//non (pre is all numbers)SYSTEM.OUT.PRINTLN ("Input + pre +" is not a number, please re-enter "); Break;//this exits the for loop, and then executes the while loop again, re-entering the number } Else{Str[i]= Integer.parseint (pre);//converts a numeric string to an int type number} Count++;//count will only be +1 after each data entry is performed } if(count==6) Break;//This exit is the while loop. } for(inti=0;i<6;i++) {//Output Print Numbers if(i==0) {System.out.print (str[i]); } Else{System.out.print (","+Str[i]); } } }}
Java input numbers are stored in an array (with character detection)