课程: Java 8+ Essential Training: Syntax and Structure

今天就学习课程吧!

今天就开通帐号,24,600 门业界名师课程任您挑!

Create looping code blocks

Create looping code blocks

- [Instructor] Java provides a number of ways of looping through collections of data. In this project, loops, I've created an array of strings. The array is private to the class, that means it can't be accessed outside of the class, and it's static which means it belongs to the definition of the class rather than to an instance of the class. It's an array of strings indicated by the type and the pair of brackets, and the name is months. To create the array I've used notation that uses braces wrapped around a comma delimited list. So I have an array containing 12 values. One value for each month of the year. I'm going to demonstrate how to loop through this data using four different kinds of loops: an incrementing loop, a for each loop, a while loop, and a do while loop. And I'll start with an incrementing loop. IntelliJ IDEA lets you create this code very quickly. Type fori, IntelliJ IDEA calls this an iteration loop. Press Enter or Return and that expands to a simple loop. An…

内容