Java loop puzzles

Source: Internet
Author: User

 

Bloch talked about many Java puzzles. Today I will share them with you.

0-cycle subject

Please write a variable declaration and place it before the following loop to make this loop an infinite loop.

For (INT I = start; I <= start + 1; I ++ ){

}

Here, start is an undefined variable. We need to define it.

If you are familiar with int, you may get the correct answer:

Int start = integer. max_value-1;

Why? Haha, because Int. max_value + 1 = int. Min-value.

 

You need to consider the following. # ^ _ ^ #

1 loop Operator

What kind of statement can make the following loop infinite?

While (I = I + 1 ){

}

2. The Bride of the loop

Provide an I statement so that the following loop is an infinite loop.

While (I! = I ){

}

3. The love of the loop Operator

Provide an I statement so that the following loop is an infinite loop.

While (I! = I + 0 ){

}

4. The ghost of the loop

Provide an I statement so that the following loop is an infinite loop.

While (I! = 0 ){

I >>>= 1;

}

5. cursing the loop

Provide declarations on I and j so that the following loop is an infinite loop.

While (I <= J & J <= I & I! = J ){

}

6. The person in the loop met the prodigal person.

Provide an I statement so that the following loop is an infinite loop.

While (I! = 0 & I =-I ){

}

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.