📄 lightstring.java
字号:
// Introduced in Chapter 3/** A string of Lights, as used in Christmas decorating. */public class LightString { /** The Lights in this LightString. */ private Light[] bulbs; /** Every other Light is a ColoredLight. */ public LightString(int size) { bulbs = new Light[size]; for (int i = 0; i < size; i++) { if (i % 2 == 0) { bulbs[i] = new Light(); } else { bulbs[i] = new ColoredLight(); } } } /** Turn all of the Lights in the LightString on or off. */ public void setOn(boolean on) { for (Light b : bulbs) { b.setOn(on); } } public String toString() { String result = ""; for (Light b : bulbs) { result += b; } return result; } /** Create a LightString, print it, turn it on, and print it again. */ public static void main(String[] args) { LightString lights = new LightString(20); System.out.println(lights); lights.setOn(true); System.out.println(lights); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -