题目:创建 7 个对象,在屏幕上显示彩虹的 7 种颜色。
示例输出:
红色
橙色
黄色
绿色
蓝色
靛色
紫色
每个对象在创建后都会显示特定的颜色。
要求:
-
该程序应输出文本。
-
你需要创建 7 个负责颜色的不同对象。
-
创建对象的顺序必须与彩虹中的颜色顺序相对应。
-
不要更改负责颜色的类。
-
所显示的文本必须与任务条件匹配
public class Solution {
public static void main(String[] args) {
Red color1 = new Red();
Orange color2 = new Orange();
Yellow color3 = new Yellow();
Green color4 = new Green();
Blue color5 = new Blue();
Indigo color6 = new Indigo();
Violet color7 = new Violet();
}
public static class Red {
public Red() {
System.out.println("红色");
}
}
public static class Orange {
public Orange() {
System.out.println("橙色");
}
}
public static class Yellow {
public Yellow() {
System.out.println("黄色");
}
}
public static class Green {
public Green() {
System.out.println("绿色");
}
}
public static class Blue {
public Blue() {
System.out.println("蓝色");
}
}
public static class Indigo {
public Indigo() {
System.out.println("靛色");
}
}
public static class Violet {
public Violet() {
System.out.println("紫色");
}
}
}
output:
红色
橙色
黄色
绿色
蓝色
靛色
紫色