1/5
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Which of the following is a proper way to declare and initialize an int variable in Java?
int myNumber = 10;Consider the following code snippet.
public static void main(String args[]){
final int z;
z = 20;
z = 30;
System.out.println(z);
}What value of z is actually printed?
This code gives an error.
What are the memory values associated with the variables x, y, and z after the code snippet below executes?
int x = 7;
double y = 2.0;
boolean z = false;
x = x + 3;
z = true;x holds the int value 10, y holds the double value 2.0 and z holds the boolean value true.
Which of the following variable names follows best practices for naming a variable?
5apples
someVariable
applesnum
numApples
numApples
What does the keyword final do?
It prevents variables from being altered.
What will be the output of the following code snippet:
public class Variables
{
public static void main(String[] args)
{
int totalBirds = 150;
double averageTime = 45.7;
String mostCommon = "Mallard Duck";
System.out.println("Bird Watching Results");
System.out.print("Total birds seen: ");
System.out.println(totalBirds);
System.out.print("Average time between sightings: ");
System.out.println(averageTime);
System.out.print("Most common bird seen was ");
System.out.println(mostCommon);
}
}Bird Watching Results
Total birds seen: 150
Average time between sightings: 45.7
Most common bird seen was Mallard Duck