Java Reference
In-Depth Information
{
//variable declaration
//executable statements
2
}
}
a.
Write Java statements that declare the following variables:
num1
,
num2
,
and
num3
, and
average
of type
int
.
b.
Write Java statements that store
125
into
num1
,
28
into
num2
, and
-25
into
num3
.
c.
Write a Java statement that stores the average of
num1
,
num2
, and
num3
into
average
.
d.
Write Java statements that output the values of
num1
,
num2
,
num3
, and
average
.
e.
Compile and run your program.
3.
Repeat Exercise 2 by declaring
num1
,
num2
, and
num3
, and
average
of type
double
. Store
75.35
into
num1
,
-35.56
into
num2
, and
15.76
into
num3
.
4.
Consider the following program segment:
//import classes
public class
Exercise4
{
public static void
main(String[] args)
{
//variable declaration
//executable statements
}
}
a.
Write a Java statement that imports the
class
Scanner
.
b.
Write a Java statement that declares
console
to be a
Scanner
object for
inputting data from the standard input device.
c.
Write Java statements that declare and initialize the following named
constants:
SECRET
of type
int
initialized to
11
;
RATE
of type
double
initialized to
12.50
.
d.
Write Java statements that declare the following variables:
num1
,
num2
,
and
newNum
of type
int
;
name
of type
String
;
hoursWorked
and
wages
of type
double
.
e.
Write Java statements that prompt the user to input two integers
and store the first number into
num1
and the second number into
num2
.
Search WWH ::
Custom Search