Java Basics (operator/select struct statement/loop Structure statement/method/identifier)One, Java identifiersA sequence of characters named for a class, interface, method, and so on.1. Identifier composition(1) English letter case;(2) Number (cannot begin with a number);(3) $ and _.2. Naming rulesConstants: Each single letter is capitalized, and if it consists o
; k ) TestFunction (k, J, i);On the basis of scenario one, this scheme puts the instantiation of the cyclic variables out of the loop, which can further reduce the number of instances of the related cyclic variables, and the scheme time-consuming situation is as follows:
Variable
Instantiation (number of times)
Initialization (number of times)
Comparison (number of times)
Self-increment (number of times)
way to find and locate errors.
Solution One: Read the code and add the output statementSolution Two: Program debugging
Program Debugging steps:
Demo Example: Using the while loop output variable i,i
On-Machine Exercise: Complete the demo example and master the program debugging method.Analysis on the structure of do-while cyclic
We've already done the basic operation of the array, and now we're going to talk about the for every loop in Java, and remember when I said for the for loop that there was a for every loop, but it wasn't detailed at the time because the For Each loop was for the array.The Fo
ArrayList and LinkedList normal for loop traversalFor most Java programmer friends, it is possible to use the most commonly used list is ArrayList, for ArrayList traversal, generally use the following wording: Public Static void Main (string[] args) { Listnew arraylist() ; for (int i = 0; i ) arraylist.add (i); for (int i = 0; i ) System.out.println (Arraylist.get (i));If you
At some point, we need to forcibly terminate this or end loop when certain conditions arise, instead of waiting for the loop condition to be false, continue (ending this loop), break (jumping out of the loop body) is provided in Java to control the looping structure. In addi
JAVA Learning Section ...... Thoughts and conditions in the loop-general Linux technology-Linux programming and kernel information. The following is a detailed description. All the friends who have used JAVA loops know that while (condition), do... while (condition)
And for (a; B; c. I just want to talk about it after I start learning.
Use the most commonly used
A cyclic statement is introduced in Java programming. There are three common forms of circular statements:For statement, while statement, Do/while statement. The following will be described in detail on a case by case basis. The basic structure of a For statement for statement is as follows:For (initialize an expression; Judge an expression; increment (decrement) an expression) {Execute the statement; A section of code}
Initialization express
ArrayList and LinkedList normal for loop traversalFor most Java programmer friends, it is possible to use the most commonly used list is ArrayList, for ArrayList traversal, generally use the following wording:void Main (string[] args) { listnew arraylist( int i = 0; I (int i = 0; i ) System.out.println (Arraylist.get (i));} If you want to use LinkedList in the future, maybe some friends will go thro
JAVA basics/Lesson 17th: control procedures/java while and DO-WHILE and FOR loop statements, whiledo-while
1. Repeated execution when the condition is true
As long as the expression in the while clause is true, it will be continuously executed cyclically.
Public class HelloWorld {public static void main (String [] args) {// print 0 to 4 int I = 0; while (I 2. If
;>> unsigned Right shift "high always 0"=, |=, ^=, ~=, >>=, >>>=, Such as:int i = 13;int j = 12;int result = i j; 12In-system:Binary, consisting of 0 and 1Note: The data stored in the computer is in binary form.There is no binary literal in JavaOctal, "0,7"Note:Java has 8 binary literals, starting with 0Such as:int i = 017; OK, equivalent to 10 binary: 15Decimal, [0,9]> 2: In addition to 2 methodsSuch as:i = 19; = "100112-10: The method of adding the sum of the exponentiationSuch as:Suppose the
1.while Cycle Structure Grammar: while (loop condition) { // loop Action } While loop structure Flowchart: Example:1 int i = 1; 2 while (i ) {3 System.out.printlen ("good study"); 4 i + +; 5 }Note: The content in the parentheses after the keyword while is the while loop
frees the variable's storage space.Nested loopsIf the number of cycles in the outer loop is m times, the number of cycles in the loop is n times, then the number of cycles in the inner loop needs m * n times. Nesting loops Note: 123. Avoid too many and too deep loop nesting structures as much as possibleNested
Learn to program Java Learning while the loop is published, welcome to visit through Xuebiancheng8.comThe previous analysis of Java's Process control is divided into select structure, loop structure, wherein the loop structure is divided into while,do...while and for loopBelow to analyze the while
Loop and string processing are worth noting during system performance optimization. In terms of mentality, we must not put our own eyes on ten or hundreds of cycles, nor treat the strings we want to process as ten or twenty characters. Every time a loop is encountered, it should be assumed that the loop is more than ten thousand times. Each time the string to be
The previous analysis of Java's Process control is divided into select structure, loop structure, wherein the loop structure is divided into while,do...while and for loopBelow to analyze the while loop in the next loop structureWhy should there be a while loop in
has been executing in the while, it needs to occupy the CPU. However, the scheduling of threads is the responsibility of the JVM or the operating system, not that thread A has been in the while loop, and thread B is not consuming the CPU. For thread A, it is equivalent to a "compute-intensive" job. If our while loop is constantly testing whether a condition is set up, this is a waste of CPU, referring to a
In life, some actions need to be repeated to complete the task. If you want to participate in the 10000-meter long-distance race, you need to repeatedly run 25 laps around the 400-meter track. When implementing functions in Java, you often need to repeat some code. For example, in order to express "strong love", we hope to output 1000 lines of "I Love course network !". Obviously, it is
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.