This is the 7th day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021

Like it and see. Make it a habit. Wechat search [a coding] follow this programmer who is struggling in the Internet.

This article is included in the technical expert training, which contains my learning route, series of articles, interview question bank, self-study materials, e-books, etc. Welcome to star ⭐ ️

Topic describes

Difficulty: Easy

/** * short circuit and logic and */
public class question_03 {
   public static void main(String[] args){
       int i=5;
       boolean e = i > 6 & i++ > 7;
       System.out.println(e);
       System.out.println(i);
       e = i > 6 && i++ > 7; System.out.println(e); System.out.println(i); }}Copy the code

Write the output of the above code

knowledge

  • Relational operator
  • On the operation

Their thinking

  • Logical and (&) and short circuit and (&&) have no influence on the result judgment of the condition, but have influence on the operation of the condition itself.

  • Logic and (&) will continuously evaluate all the commands that need to be evaluated. But short-circuiting is the same as stopping when false is encountered.

Code implementation

Analysis of the

The first judgment is logical and, honest man whether true or false, do all the calculations, then i++ is executed, e=false; I = 6;

I++ is not executed, e=false; I = 6;

validation

conclusion

In order to enhance the readability of the code in the actual development, the unified use of short circuit and, and do not do any calculation in the judgment condition.

The last

One foot is difficult to go, one hand is difficult to sing, a person’s power is limited after all, a person’s journey is doomed to be lonely. When you set a good plan, with full of blood ready to set out, must find a partner, and Tang’s monk to the West, the master and his disciples four people united as one to pass the ninety-eight difficult. So,

If you want to get into a big factory,

To learn data structures and algorithms,

If you want to keep brushing,

To have a group of like-minded people,

Please join the team to brush the questions