Java Learning FAQs

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.