Exercise 3-11 (AllTheColorsOfTheRainbow)

Chapter_3     Exercise_3-10     Show_Properties Exercise_3-12







Exercise 3-11     TIJ, p. 61


Exercise 3-11: (1) Turn the AllTheColorsOfTheRainbow example into a program that compiles and runs.




AllTheColorsOfTheRainbow.java     TIJ, p. 60


public class AllTheColorsOfTheRainbow
{
int anIntegerRepresentingColors;

void changeTheHueOfTheColor(int newHue)
{
anIntegerRepresentingColors = newHue;
}

public static void main(String[] args)
{
AllTheColorsOfTheRainbow all = new AllTheColorsOfTheRainbow();
System.out.println(all.anIntegerRepresentingColors);
all.changeTheHueOfTheColor(1);
System.out.println(all.anIntegerRepresentingColors);
}
}
/*
javac AllTheColorsOfTheRainbow.java
java AllTheColorsOfTheRainbow
0
1
*/




Note:  See Naming_Conventions on Wikipedia, camelCase and PascalCase on Wiktionary.









Chapter_3     Exercise_3-10     Show_Properties BACK_TO_TOP Exercise_3-12



Comments

Popular posts from this blog

Contents