[Java] Experiment 8

Source: Internet
Author: User

[Java] Experiment 7 Reference Code , the code has been updated. Interested students can go to study.


1. The default package problem can be tested in experiment 6

2.?for, if, while and so on. When you include more than one statement, you need to enclose it in curly braces .

3. Why close scanner is required, can I take the test 6? (reason has been briefly updated)

?

40035 output the number of days in a month

1. A simpler way to switch-case

Switch (month) {case 1:case 3:  //Output if month equals 1 or 3  System.out.println (to);  Break;case 2:  //TODO. Note that the can use the "if" statement in "case" case 4:case 6:  //...         }

We have the coding principle: DRY (does not repeat yourself.)

2. Definition of Leap Year

Satisfy for example one of the following conditions, arbitrarily. That is a leap year. Consider the year n,

??? -if n can be divisible by 4. But not divisible by 100.

??? -if n can be divisible by 400

3. Local execution is correct, submit "answer wrong" classmate, can examine for example the following case:

Year = 1900, month = 2

Year = $, month = 2

...

We have to design some cases, to verify the "special circumstances", "marginal conditions" and so on.

?

40037 number of people who failed the calculation

1. How to stop the program, please analogy 40008. Ask for odd and that question.

Update: The problem code is given in the Experiment 6 reference code.

2. In the second line output error (average output 73.75, or the number of failed to output 3) students, can participate in the experiment six "seek 1+1/2+1/3+ ... +1/n " that question, 3rd.

The popular version of the code: (I do not have the original title of the corresponding program.) To be added)

Advanced Code:

Import Java.util.scanner;public class Gradestatistics {public  static void Main (string[] args) {    Scanner in = new Scanner (system.in);    int repeat = In.nextint ();    while (repeat--! = 0) {      double gradetot = 0;  Gradetotal, the sum of the input grades      int gradecnt = 0;  Gradecount, the number of the input grades      int failcnt = 0;  Failcount, the number of the grades, which is <      (int grade = In.nextint (); grade >= 0; grade = In.nex TInt ()) {        Gradetot + = grade;        + + gradecnt;        Failcnt + = Grade < 60?

1:0; } Double average = gradetot/gradecnt; System.out.println ("average=" + math.round (average *)/100d); System.out.println ("count=" + failcnt);}}


50001

To write a function fact, notice that the function consists mainly of: return value, function name, list of references, function body.

Students who do not understand can consult the reference book on their own.


50002

This question requires the definition of the function FN, whose list of references is to fill in two parameters.


[Java] Experiment 8

Related Article

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.