Java

TOPIC 06 – VARIABLES

 

LESSON WORK

 

 

QUESTION 1


Which of the following variable names follow the Java variable naming convention rules?

 

a)    totalCents

b)    totalcents

c)     TotalCents

d)    Total cents

e)    Apples

f)      apples

g)    oranges18

h)    18oranges

 

Compare your work with a classmate.  Check the rules in the lesson note.

Place your answers inside a file named Question01 that is inside your Topic06 project folder.
 

QUESTION 2

Write the statements that do the following:

 

a)    Declare a double variable named cat.

b)    Declare and initialize an int variable to the value 8.

c)     Set the value of the variable x to 36.5.

d)    Write the statement to output the value of each variable above to the screen.

 

Place your code inside a class named Question02 inside your Topic06 project folder.

 

QUESTION 3

In the code below, what is the different between the two output statements?

 

public class Example

{

    public static void main(String[] args)

    {

       int number = 123;

       System.out.println(number);

       System.out.println("number");

    }

}

 

Place your answer inside a file named Question03 inside your Topic06 project folder.