題目:
將 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);
}
}
結果如下:
如果覺得寫的不錯的話,就用點贊來代替五星好評吧!