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
java.io.IOException —don't worry about throws
java.io.IOException ; you'll learn about this language feature in
Chapter3 . Continuing,insertthe“loopuntilCorcisinput”examplefrom
the“BreakandLabeledBreakStatements”sectionintothe main() meth-
od.Compileandrunthisapplication.Whenprompted,typeakeyandpress
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
isfollowedbyawhileloopthatoutputsthisinteger'sdigitsinreverse.For
example, 876432094 outputs as 490234678 .
Search WWH ::




Custom Search