1.2.2 Variables and Types

studied byStudied by 1 person
0.0(0)
Get a hint
Hint

Which of the following is a proper way to declare and initialize an int variable in Java?

1 / 5

6 Terms

1

Which of the following is a proper way to declare and initialize an int variable in Java?

int myNumber = 10;

New cards
2

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.

New cards
3

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.

New cards
4

Which of the following variable names follows best practices for naming a variable?

5apples

someVariable

applesnum

numApples

numApples

New cards
5

What does the keyword final do?

It prevents variables from being altered.

New cards
6

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

New cards

Explore top notes

note Note
studied byStudied by 3 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 26 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 9 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 12 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 18 people
Updated ... ago
4.0 Stars(1)
note Note
studied byStudied by 8 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 6 people
Updated ... ago
4.0 Stars(1)
note Note
studied byStudied by 30439 people
Updated ... ago
4.4 Stars(24)

Explore top flashcards

flashcards Flashcard67 terms
studied byStudied by 5 people
Updated ... ago
4.0 Stars(1)
flashcards Flashcard81 terms
studied byStudied by 10 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard48 terms
studied byStudied by 1 person
Updated ... ago
5.0 Stars(1)
flashcards Flashcard92 terms
studied byStudied by 13 people
Updated ... ago
5.0 Stars(2)
flashcards Flashcard141 terms
studied byStudied by 10 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard109 terms
studied byStudied by 75 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard60 terms
studied byStudied by 1 person
Updated ... ago
5.0 Stars(1)
flashcards Flashcard34 terms
studied byStudied by 29 people
Updated ... ago
5.0 Stars(1)