Java 习题(7)

题目:
将 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);
    }
}

结果如下:
在这里插入图片描述
如果觉得写的不错的话,就用点赞来代替五星好评吧!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章