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
}
Here, start is an undefined variable. We need to define it.
If you are familiar with int, you ma
Iterator is an iterator interface (Interface) in Java that is used to provide standard Java iteratorsIterator supports generics because the type that the collection (Collection) class can mount is indeterminate, and the object type is removed from the collection, and the generics are told that the compiler determines the type of object to mount, and that the value does not need to be cast.For each is a new
My Java development and learning journey ------> use a recursive loop algorithm to list all the data counts in the array ------ Recursion
The interview questions are as follows: list all the combinations of numbers in an array, for example, columns 1 and 2 are 1, 2, 12, and 21.
(The interview questions are from the Java
1. How to jump out of the current multi-nested loop in java? In java, if you want to jump out of multiple nested loops, you can define a label before the loop statement, and then use the break statement with the label in the code in the loop body to jump out of the outer
1 , JAVA Performance Tuning-do not use expressions in loop conditionsWhen we learn about Java Performance Tuning, we often see this passage: In the case of No compilation optimization, in the loop, the loop condition will be repeatedly calculated, if you do not use complex e
For loopThe number of times the For loop executes is determined before execution. The syntax format is as follows: for (initialize; Boolean expression; update) {// code statement }There are several explanations for the For loop:
The initialization step is performed first. You can declare a type, but you can initialize one or more loop control variables,
The FOR Loop statement is a very useful looping statement in Java programming. A For loop can be used to repeatedly execute a statement until a condition is satisfied. The addition of the enhanced foreach syntax in Java 5 is also very useful.1. For statementThe number of times the For
The For-each loop is also called an enhanced for loop, or a foreach loop.The For-each loop is a new feature of JDK5.0 (other new features such as generics, auto-boxing, etc.).The addition of the For-each loop simplifies the traversal of the collection.Its syntax is as follows:for (type Element:array){SYSTEM.OUT.PRINTLN
The Java language does not provide a goto statement to control the jump, which improves the readability of program flow control, but reduces the flexibility of programmatic controls. To compensate for this deficiency, Java provides continue and break to control the loop structure, and in addition, return can end the entire method and end a
instructions and flowchart: 1. perform the loop body first2. post-judgment Boolean expression3. The loop body is executed at least onceDo-while Loop Code: Package com.oliver.test; Public class Dowhile { publicstaticvoid main (string[] args) { int i = 1; Do { = i+1; I++ ; } while (i); System.out
Java enhanced for LoopJava5 introduces an enhanced for loop that is primarily used for arrays . The Java enhanced for loop syntax format is as follows :( in simple terms, the elements in the array are sequentially output )for ( declaration statement : expression ){code sentences}declaration statement: declares a n
In practical programming, it is sometimes necessary to jump out of a loop when a conditional statement is matched. In Java, it is controlled by the break and continue statements."Break" statementThe "break" statement is used to end the loop, that is, all loops behind it are no longer executed.Example: Calculate the result of a 1+2+3+4......+100.public class examp
Use the FOR Loop statement to output the following funnel effect:+------+|\..../|| \.. / || \/ || /\ || /.. \ || /....\|+------+Code: (See the code header for more lines of comment)In this example code, a constant height is used, which refers to half of the interior height value of the funnel as a constant value./** +------+ height:3 * |\..../| First line: Number of spaces: 0 Pips: 4 spaces: 0 * | \..
The java1.5 version introduces an enhanced for loop, which is similar in principle to for loops.Syntax declaration: for (expression: conditional expression)Example: For(String str: set) Explanation: Set represents the set set, and STR represents the type stored in the set set.The code examples are as follows:Set New Hashset(); Iteratorset while (It.hasnext ()) { = It.next (); System. out forset) {
1.breakBreak is used to completely end a loop and jump out of the loop body. Regardless of the loop, once a break is encountered in the loop body, the system will completely end the loopIn Java is the label definition, the tag is a colon immediately following the English (:)
Complete the same function, with different code to achieve, there may be a large difference in performance, so for some performance-sensitive modules, it is necessary to optimize the code. Today, let's talk about Java code optimization, and today we're going to focus on optimizations for the for (while and so on) loops.As one of the three major structures of the cycle, we are often used when writing code. The loop
1. Today basically class is to review the previous OHJob Joseph Ring, 30 people in a circle, starting from a person to count 1, the next number of 2, count to 9 on (^_^)/~~ bye, out, the next person continues to count 1 .... Ask the remaining 15 people to be Christians? The amount ... Wrong...... The rest of the 15 people are standing in a position. Use an array to solve the ... The initialization is 0, the outgoing is assigned a value of 1, the loop
Java Script LoopA. For loopBasic format: for (initialize variable; conditional control; increment) {Loop statement}Execution sequence: 1. Initialize variable 2. Determine if the condition 3 conforms to the execution Loop statement 4 increment or decrementAdvanced: Multi-layer nested for loop outermost
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.