while loop: a straightforward operation that is repeatedly performed under a certain condition
do while loop: Compared with the while loop, the do while loop is executed first, and then judged
for loop: Under certain conditions, an operation is performed with a certain regularity
while(Boolean expression){
Loop body; // As long as the expression result is true, the loop content is executed
}
do{
Loop body; //Execute the loop once, and then determine the expression result
}while(Boolean expression) ;
for (initialization①; Boolean expression②; loop condition update④){
Loop body ③; //The execution sequence is as marked above. As long as the Boolean expression is still satisfied after the loop condition is updated, the loop body will continue to be executed.
}
for (declaration variable: array name) {
System.out.println(variable name); //The size of the variable name does not need to be defined. In this loop, it will be customized as The length of the array -1
}
Find the cumulative value of the integers 1 to 100, but it is required to skip all numbers with a single digit of 3.
# ***** *******
*********
## 5.Lucky guess: The game randomly gives a number from 0 to 99 (including 0 and 99), and then asks you to guess what number it is. You can guess a number at random, and the game will tell you whether it's too big or too small, narrowing down the results. After several guesses and hints, the answer was finally revealed. During the game, record the number of times you finally guessed correctly, and announce the result after the game is over.
Tips: Generate random numbers between 0 and 99: int number = (int)(Math.random()*100) 6. Enter two positive integers m and n, Find their greatest common divisor and least common multiple. 7. Find the value of s=a aa aaa aaaa aa...a, where a is a number. For example, 2 22 222 2222 22222 (a total of 5 numbers are added at this time), and the addition of several numbers is controlled by the keyboard.
8. A ball falls freely from a height of 100 meters. Each time it hits the ground, it bounces back to half of its original height. When it falls again, how many meters does it pass in total when it hits the ground for the 10th time? How high is the 10th rally?
9. There are four numbers 1, 2, 3, and 4. How many different three-digit numbers can be formed without repeated numbers? How many are they?
10. Request the output sequence 1 2 3 5 8 13 21 .......
Related articles:
javascript process control Statements while loop and do... Detailed explanation of while loop syntax examplesJavaScript For loop and While loop
Methods without parameters and return values - the latest Java complete video tutorial
The above is the detailed content of A brief introduction to Java loop structures: while loop and do while loop. For more information, please follow other related articles on the PHP Chinese website!