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);
    }
}

結果如下:
在這裏插入圖片描述
如果覺得寫的不錯的話,就用點贊來代替五星好評吧!

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