Code sharing of several loop examples in Java programming

About the content of Java loop, it is still commonly used in programming. Let's share some sample code of loop for practice.

1. The loop outputs all numbers between 1 and 100 that can be divided by 3 or 4.

2. The cycle outputs all numbers between 200 and 300 that can be divided by 5, or that can be divided by 2 and can be divided by 3.

3. Loop outputs all numbers in 1 to 2000 that can be divided by 4 but cannot be divided by 100, or that can be divided by 400.

4. Calculate the result of 1 + 2 + 3 +... + 100.

5. Calculate the result of 1 * 2 * 3 *... * 10.

6. Calculate 1 + 1 / 4 + 1 / 9 ++ 1/(20*20)

7. Input an integer into the variable n. if the integer is greater than 0, calculate the result of 1 + 2 + 3 +... + (n-1) + n. otherwise, output "the input data is wrong

8. Input the scores of 5 students in a circle, and calculate the total score and average score of these 5 students

9. First, the user is required to input the number of students into the variable n. if this number is greater than 0, it will cycle n times to receive the scores of n students and calculate the total score and average score. Otherwise, the number of students output cannot be negative

10. Ask "wife, do you love me?", If the answer is "love", then end the cycle, otherwise continue to ask. Describe the story with a program

11. Loop input strings, connect these input strings, end the loop when the input string is "ESC", and finally display the connected string. For example, enter ABC, enter def, and enter ESC to output ABCDEF

12. Enter the year and month to print the calendar of the month. For example, enter September 2011 to print the calendar of September 2011

summary

The above is all about the code sharing of several loop examples of Java programming in this paper. I hope it will be helpful to you. Interested friends can continue to refer to this site: ArrayList uses the remove method to remove elements in the for loop, introduction to the method, detailed explanation of Java multithreaded forkjoinpool instance, etc. if there are deficiencies, please leave a message to point out. Thank you for your support!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>