(2-3) Flashcards

(76 cards)

1
Q

What will be displayed after the following statements have been executed?

Final double x;
x = 54.3;
System.out.println(“x = “ + x);

A

Nothing, it’s an error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a result of the following expression?

10 + 5 * 3 - 20

A

5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

public class test {
public static void main(String args[] )
{
int value1 = 9;
System.out.println(value1);
int value2 = 45;
System.out.println(value2);
System.out.println(value3);
value = 16;
}
}

A

Nothing, it’s an error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

To compile a program named First, use the following command

A

javac First.java

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which of the following is a valid Java statement?

A

String str = “John Doe.”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which of the following is NOT a primitive data type?

A

String

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Given the declaration double r; which of the following statements is invalid?

A

r = 2.9X106;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which of the following is NOT a rule that must be followed when naming identifiers?

A

Identifiers can contain spaces

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

To display the output on the next line, you can use the println method or use this escape sequence in the print method:

A

\n

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When saving a Java source file save it with an extension of:

A

.java

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

This is a variable whose content is read only and cannot be changed during the program’s execution:

A

Named constant

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

A variable’s scope is the part of the program that has access to the variable

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The boolean data type may contain values in the following range of values:

A

True or false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

A java program must have at least one of these:

A

Class definition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In the following Java statement what value is stored in the variable name?

Str = “John Doe”;

A

The memory address where “John Doe” is located

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When the + operator is used with strings, it is known as:

A

String concatenation operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

If x has been declared as an int, which of the following statements is invalid?

A

x = 1,000;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

In Java, it’s standard practice to capitalize the first letter of:

A

Class names

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Which Scanner class reads an int?

A

nextInt()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

If the compiler encounters a statement that uses a variable before the variable is declared an error will occur.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Variables are classified according to their:

A

Data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

This is a value that is written into the code of the program

A

Literal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the result of the following code?

25 - 7 * 3 + 12 / 3

A

8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

In Java, the beginning of a comment is marked with:

A

//

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Which of the following is valid?
float w; w = 1.0f;
26
Which of the following statements correctly creates a Scanner object for keyboard input?
Scanner keyboard = new Scanner(System.in);
27
What will be displayed as a result of the following code: int x = 5, y = 20; x += 32; y /= 4; System.out.println("x = " + x + ", y = " + y);
x = 37, y = 5
28
What will be the value of z as a result of executing the following code? int x = 5, y = 28; float z; z = (float) (y/x);
z = 5.0
29
What would be printed out as a result of the following code? System.out.println("The quick brown fox" + "jumped over the \n" "slow moving hen.");
Nothing, it's an error
30
What will be displayed as a result of the following code? int x = 6 string msg = "I am enjoying this class";
I am enjoying this class. I AM ENJOYING THIS CLASS i am enjoying this class Character at index x = n msg has 25 characters
31
Character literals are enclosed in __________; string literals are enclosed in ____________
Single quotes, double quotes
32
The primitive data types only allow a(n) ___________ to hold a single value
Variable
33
What is the result of the following expression? 25 / 4 + 4 * 10 % 3
7
34
In Java ______ must be declared before it can be used
Variables
35
This is a named storage location in the computer's memory
Variable
36
What will be displayed as a result of the following code? int x = 578; System.out.println("There are" + x + 5 + "\n" + "hens in the house.");
There are 5785 hens in the house
37
What will be the value of z after the following statement executes? int x = 4, y = 33; double z; z = (double) (y/x);
8.0
38
Assuming that pay has been declared a double, the following statement is valid: Pay = 2,888;
False
39
What will be the value of ans after the following code has been executed? int x = 90, y = 55, ans = 10; if (x == y); ans *= 2;
20
40
A block of code is enclosed in a set of:
braces { }
41
Enclosing a group of statements in a set of braces creates a:
block of statements
42
When two Strings are compared using the compareTo method, the cases of the two strings are not considered
False
43
This type of operator determines whether a specific relationship exists between two values:
Relational
44
A local variable's scope always ends at the closing brace of the block of code in which it is declared
True
45
What will the value of ans after the following code has been executed? int ans = 10; int x = 65; int y = 55; if (x >= y) ans = x + y;
120
46
What would be the value of bonus after the following statements are executed? int bonus, sales = 1250; if (sales > 1000) bonus = 100; if (sales > 750) bonus = 50; if (sales > 500) bonus = 25; else bonus = 0;
25
47
If chr is a character variable, which of the following if statements are written correctly?
if (chr == 'a')
48
The if/else statement will execute one group of statements if its boolean expression is true or another group if its boolean expression is false
True
49
_______ works like this: If the expression on the left side of the && operator is false, the expression on the right side will not be checked
Short-circuit evaluation
50
What is the value of ans after the following code has been executed? int x = 35; int y = 20, ans = 80; if (x > y); ans += y;
100
51
This is a boolean variable that signals when some condition exists in the program
Flag
52
If str1 and str2 are both strings, which of the following expressions will determine whether they are equal?
2 and 3 The statements that uses equals to and compareTo
53
Which of the following is the not equal operator?
!=
54
In most editors, you are indenting by one level each time you press this key:
tab
55
A Boolean expression is one that is either:
true or false
56
A flag may have the values
true or false
57
What will the values of ans, x, and y after the following statements are executed? int ans = 0, x = 15, y = 25; if ( x >= y) { ans = x + 10; x -= y; } else { ans = y + 10; y += x; }
Ans = 35, x = 15, y = 40
58
In an if/else statement, if the boolean expression is false:
The statement or block following the else is executed
59
What will be the value of x after the following code is executed? int x = 75; int y = 60; if (x > y) x = x - y;
15
60
What is the value of x after the following code has been executed? int x = 75; int y = 90; if (x != y) x += y;
165
61
To do a case insensitive compare which of the following could be used to test the equality of two strings str1 and str2?
(str1.equalsIgnoreCase(str2)) and (str1.compareToIgnoreCase(str2) == 0)
62
What would be the value of bonus after the following statements are executed? int bonus, sales = 85000; char dept = 'S'; if (sales > 100000) if (dept == 'R') bonus 2000; else bonus = 1500; if (sales > 75000) if (dept == 'R') bonus 1250; else bonus = 1000; else bonus = 0;
1000
63
What will the values of ans, x, and y after the following statements are executed? int ans = 35, x = 50, y = 50; if ( x >= y) { ans = x + 10; x -= y; } else { ans = y + 10; y += x; }
ans = 60, x = 0, y = 50
64
Which of the following is the correct boolean expression to test for: int x, being a value between, but not including, 500 and 650, or int y not equal to 1000?
((x > 500 && x < 650)) || (y != 1000))
65
Which of the following tests the char variable chr to determine whether it is NOT equal to the character B?
if (chr != 'B')
66
Programs never need more than one path of execution
False
67
If you prematurely terminate an if statement with a semicolon, the compiler will
Not display and error message Assume you are placing a null statement Answer - All of these
68
What would be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 1250; if (purchase > 1000) discountRate = 0.05; if (purchase > 750) discountRate = 0.03; if (purchase > 500) discountRate = 0.01; else bonus = 0;
0.01 (check this answer again)
69
The expression tested by an if statement must evaluate to:
true or false
70
The ________ statement is used to make simple decisions in Java
if
71
This operator uses two operands:
binary
72
Because the && operator performs short-circuit evaluation, your boolean expression will usually execute faster if the subexpression that is most likely false is on the left side of the operand
True
73
What would be the value of bonus after the following statements are executed? int bonus, sales = 10000; if (sales < 5000) bonus = 200; else if (sales < 7500) bonus 500; else if (sales < 10000) bonus = 750; else if (sales < 20000) bonus = 1000; else bonus = 1250;
1000
74
What would be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 100; if (purchase > 1000) discountRate = 0.05; else if (purchase > 750) discountRate = 0.03; else if (purchase > 500) discountRate = 0.01;
0.0
75
What would be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 1250; char cust = 'N'; if (purchase > 1000) if (char cust == 'Y') discountRate = 0.05; else discountRate = 0.04; if (purchase > 750) if (char cust == 'Y') discountRate = 0.04; else discountRate = 0.03; else discountRate = 0;
0.04 (check this answer again)
76
If str1 and str2 are both strings which of the following will correctly test to determine whether str1 is less than str2?
3 = (str1.compareTo(str2) < 0)