国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
注意點(diǎn) " >注意點(diǎn)
注意點(diǎn)2
Home Java JavaInterview questions Ele.me's written test questions seem simple, but it stumps a lot of people

Ele.me's written test questions seem simple, but it stumps a lot of people

Aug 24, 2023 pm 03:29 PM
java interview questions


Please read the question

Please write down what this code outputs?

/**
 * @author 面試專(zhuān)欄
 * @date 2021/7/11 13:57
 */
public class Test1 {
    public static void main(String[] args) {
        //輸出什么?
        test();
    }

    public static void test() {
        for (int i = 4; i > 0; i--) {
            int j = 0;
            do {
                j++;
                if (j == 2) {
                    break;
                }
            } while (j <= i);
            System.out.print(j);
        }
    }
}

Seeing this question, many people will think it is too simple. In fact, this question examines three knowledge points;

  • forloop
  • do...whileLoop
  • breakExit

Don’t underestimate me, too I have asked many people, and the answers are all strange. Four answers appear most frequently:

  • 第一個(gè):4321
  • 第二個(gè):1232
  • 第三個(gè):2211
  • 第四個(gè):2222

你覺(jué)得是哪個(gè)?還是覺(jué)得都不是?

注意點(diǎn)

注意點(diǎn)1

do...while循環(huán)是while循環(huán)的變種,在檢查條件是否為真之前,該循環(huán)其實(shí)已經(jīng)執(zhí)行過(guò)一次了,然后在檢查條件是否為真,如果為true,就重復(fù)執(zhí)行這個(gè)循環(huán)。注意:只要循環(huán)體中執(zhí)行break后也會(huì)結(jié)束循環(huán)。

注意點(diǎn)2

for(表達(dá)式1;表達(dá)式2;表達(dá)式3){
//循環(huán)體
}

這個(gè)循環(huán)體執(zhí)行步驟如下:

  • The first step: execute initialization: expression 1 (will only be executed once)
  • The second step: execute expression 2, if expression 2 If the result is false, the loop ends, otherwise the loop body is executed, and then expression 3 is executed.
  • Step 3: Loop step 2, when the result of expression 2 is false , exit the loop, or encounter the return, break keywords.

Ontology analysis

  • ##When entering the for loop body for the first time, i=4, and then included in the do...while loop body. At this time, j=0, and then this loop continues to execute j until j=2 or j>i exits the loop body. Obviously, j=2 at this time, also That is, the output at this time is 2.

  • The next time the for loop, i=3, the output is still 2,

  • The next for loop, i=2, the same output is still 2,

  • The next for loop, i=1, the same output The result is 2. At this time, the i-- operation of the foe loop is executed, i=0, and the condition of i>0 is not met. At this time, the for loop exits.

So, the final output result is:

2222.

Postscript

Don’t underestimate the written test questions of many companies. There are pitfalls. If you are not careful, you will be wrong. fell in. When you encounter this kind of written test question about cycles, I suggest you think calmly and take it step by step.


In the written test, the more seemingly simple the question is about coding, the less we should take it lightly.

The above is the detailed content of Ele.me's written test questions seem simple, but it stumps a lot of people. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Interviewer: Spring Aop common annotations and execution sequence Interviewer: Spring Aop common annotations and execution sequence Aug 15, 2023 pm 04:32 PM

You must know Spring, so let’s talk about the order of all notifications of Aop. How does Spring Boot or Spring Boot 2 affect the execution order of aop? Tell us about the pitfalls you encountered in AOP?

Interview with a certain group: If you encounter OOM online, how should you troubleshoot it? How to solve? What options? Interview with a certain group: If you encounter OOM online, how should you troubleshoot it? How to solve? What options? Aug 23, 2023 pm 02:34 PM

OOM means that there is a vulnerability in the program, which may be caused by the code or JVM parameter configuration. This article talks to readers about how to troubleshoot when a Java process triggers OOM.

5 String interview questions, less than 10% of people can answer them all correctly! (with answer) 5 String interview questions, less than 10% of people can answer them all correctly! (with answer) Aug 23, 2023 pm 02:49 PM

?This article will take a look at 5 interview questions about the Java String class. I have personally experienced several of these five questions during the interview process. This article will help you understand why the answers to these questions are like this.

Ele.me's written test questions seem simple, but it stumps a lot of people Ele.me's written test questions seem simple, but it stumps a lot of people Aug 24, 2023 pm 03:29 PM

Don’t underestimate the written examination questions of many companies. There are pitfalls and you can fall into them accidentally. When you encounter this kind of written test question about cycles, I suggest you think calmly and take it step by step.

Last week, I had an interview with XX Insurance and it was cool! ! ! Last week, I had an interview with XX Insurance and it was cool! ! ! Aug 25, 2023 pm 03:44 PM

Last week, a friend in the group went for an interview with Ping An Insurance. The result was a bit regretful, which is quite a pity, but I hope you don’t get discouraged. As you said, basically all the questions encountered in the interview can be solved by memorizing the interview questions. It’s solved, so please work hard!

Novices can also compete with BAT interviewers: CAS Novices can also compete with BAT interviewers: CAS Aug 24, 2023 pm 03:09 PM

The extra chapter of the Java concurrent programming series, C A S (Compare and swap), is still in an easy-to-understand style with pictures and texts, allowing readers to have a crazy conversation with the interviewer.

Interviewer: Tell me about the class loading process (10 diagrams) Interviewer: Tell me about the class loading process (10 diagrams) Aug 23, 2023 pm 03:05 PM

When we want to use a class, we need to load the class into memory through ClassLoader.

A question asked in almost all Java interviews: talk about the difference between ArrayList and LinkedList A question asked in almost all Java interviews: talk about the difference between ArrayList and LinkedList Jul 26, 2023 pm 03:11 PM

The data structure of Java is the focus of the interview. Anyone who has participated in a Java interview must have some experience. When interviewers ask such questions, they often want to check whether you have studied the underlying structures of commonly used data types in Java, rather than simply staying at the level of "knowing how to use".

See all articles