lightstring.java
来自「java版的数据结构的完全代码 免费提供了 学习数据结构的请下载」· Java 代码 · 共 44 行
JAVA
44 行
// 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 + =
减小字号Ctrl + -
显示快捷键?