题目:
将 AllTheColorsOfTheRainbow 这个示例改写成一个程序,然后编译,运行。
解答:
先把 AllTheColorsOfTheRainbow 的程序段写出来:
class AllTheColorsOfTheRainbow {
int anIntegerRepresentingColors;
void changeTheHueOfTheColor(int newHue) {
// ...
}
}
然后用上面的代码段来进行修改成能运行的代码
class AllTheColorsOfTheRainbow {
int anIntegerRepresentingColors;
void changeTheHueOfTheColor(int newHue) {
anIntegerRepresentingColors = newHue;
System.out.println(anIntegerRepresentingColors);
}
}
public class chapterOne {
public static void main(String[] args){
AllTheColorsOfTheRainbow eleven = new AllTheColorsOfTheRainbow();
eleven.changeTheHueOfTheColor(2);
}
}
结果如下:
如果觉得写的不错的话,就用点赞来代替五星好评吧!