1:elipse assigns a value to the main function args parameter
1 Public classprog{2 Public Static voidMain (string[] args) {3 intn =-1;4 Try{5n = integer.parseint (args[0]);6}Catch(arrayindexoutofboundsexception e) {7System.out.println ("Please enter your score");8 return;9 }Ten grade (n); One } A //Score Level Calculation - Private Static voidGradeintN) { - if(n>100 | | n<0) theSYSTEM.OUT.PRINTLN ("Invalid input"); - Else{ -String str = (n>=90)? " ":((n>60)?" Points, belonging to B, etc. ":" points, belonging to C, etc. "); -System.out.println (n+str); + } - } +}View Code
Solution: eclipse-"Run configuration-" arguments plus parameters
2: Scanner.usedelimiter () method in Java
Reprint: Baidu Experience
In the Java language, formatted input is done through the class Java.util.Scanner.
By default, scanner uses "white space" as a delimiter to break input into tokens.
The resulting token is then converted to a different type of value using the different next methods it provides.
Check the results of the following Java programs first
The result is that because the scanner object will first skip all whitespace separators at the beginning of the input stream, and then check the information in the input stream,
Until a blank delimiter is encountered; input data: Zhong Guoren; characters following whitespace: Guoren, output is not displayed
Scanner a space as a delimiter, how do you export data that contains spaces?
In this case, you need to use the Scanner.usedelimiter () method, you can modify the delimiter to "carriage return", or other characters.
Delimiter in English means delimiter; the Usedelimiter () method defaults to a space as a delimiter, and of course it modifies, for example:
Usedelimiter (","); With ', ' as a delimiter
Usedelimiter ("\ n"); The "\ n" line break (carriage return) as the delimiter for the input.
Therefore, the above procedure can be changed to
In this way, you can output data that contains spaces.
Java Learning FAQs