Java-preliminary Understanding-Chapter III-IF statement exercises-week and season

Source: Internet
Author: User
Tags logical operators

One.

Here begins the application of the IF statement and expands the operation experiment.

In the case of judging the input data for the day of the week, it proves that I have not understood the = = comparison operator well enough to understand the if third format. The last else does not have to be followed by any conditional expression, which represents all the remaining data except for the above cases.

Two.

The first thing to understand is that the day of the week and the season is all about exercising the use of the IF statement. The If statement code block here is more complex to write than before.

Idea: At present, the Java language understanding is not deep enough, with the existing knowledge level to write, can only use if format three, and write a lot of statements.

The written form is as follows:

int x;

if (x==3)

{

System.out.println (x+ "corresponds to Spring");

}

.......

However, are there any conditional statements that can discriminate multiple forms at once?

The disadvantage is that there are too many duplicate output statements, such as SYSTEM.OUT.PRINTLN (x+ "corresponding to the Spring"); it will be written four times, summer, autumn, winter ...

In the field of programming there is a sentence that improves the reusability of code. A code with two times is possible, once more than two times, you need to rethink the writing of the Code.

There are many ways to improve the reusability of code, here only one, the connection condition statement. (This condition is referred to as multi-criteria corresponding to the same content)

How to connect a conditional statement is a logical operator. The existence of logical operators can improve the complexity of the code.

Look at the following, using a short circuit or. their knowledge of the previous points, and began to a little forgotten .

A logical operator can not only connect two expressions, as follows

An error has occurred in the video, as follows

Error: The corresponding class was not found. Cause: The class file name was incorrectly written when the Classpath,java command was set.

Here the source program is written in Iftest.java, but the class name in the code is class iftest. Therefore, even if the Iftest.java source program is compiled, the output recognizes the class file that corresponds to the class name, not the class file of the source program name. Of course, it is also possible to enable Java runtime in DOS, knocking the name of the class file.

After the previous explanation, got a simplified source program, but still not enough simplification, if the conditional statement, month==3 | | month==4 | | month==5; It still seems too long

Can be used to judge the input data, month>=3 & month<=5; & Connect Two Boolean data, the IF condition statement always represents a judgment. Here, it is also mentioned that the difference between & and &&,& need to be judged on both sides of the expression, and && only need to judge the left.

here the understanding of the IF statement is sublimated again, if the third format is actually the whole range of discrimination . Why there is a full range of discrimination, is the uncertainty of the input.

Java-preliminary Understanding-Chapter III-IF statement exercises-week and season

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.