Java Reference
In-Depth Information
2. Declare a Circle class whose main() method declares a double preci-
sion floating-point variable named PI that's initialized to 3.14159 , de-
claresadoubleprecisionfloating-point variablenamed radius that'sini-
tialized to 15 , calculates and outputs the circle's circumference ( PI times
the diameter), and calculates and outputs the circle's area ( PI times the
square of the radius). Compile and run this application.
3. Declare an Input class whose main() method is declared as follows:
public static void main(String[] args) throws —don't worry about throws ; you'll learn about this language feature in
Chapter3 . Continuing,insertthe“loopuntilCorcisinput”examplefrom
the“BreakandLabeledBreakStatements”sectionintothe main() meth-
theEnter/Returnkey.Whathappenswhenyoutypemultiplekeys( abc ,for
example) and press Enter/Return?
4. Declare a Triangle class whose main() method uses a pair of nested
forstatementsalongwith System.out.print() tooutputa10-rowtri-
angle of asterisks, where each row contains an odd number of asterisks (1,
3, 5, 7, and so on), as follows:
Compile and run this application.
5. Declarean OutputReversedInt classwhose main() methoddeclares
an int variablenamed x that'sassignedapositiveinteger.Thisdeclaration
example, 876432094 outputs as 490234678 .
Search WWH ::

Custom Search