Assignment Statements and Input - AP Computer Science A
Card 1 of 30
Which operator checks equality in Java?
Which operator checks equality in Java?
Tap to reveal answer
The '==' operator. Compares values for equality, returns boolean.
The '==' operator. Compares values for equality, returns boolean.
← Didn't Know|Knew It →
What is the output of 'System.out.println("5" + 5);'?
What is the output of 'System.out.println("5" + 5);'?
Tap to reveal answer
- String concatenation converts int to string first.
- String concatenation converts int to string first.
← Didn't Know|Knew It →
What is the purpose of 'System.in'?
What is the purpose of 'System.in'?
Tap to reveal answer
It is used for input from the keyboard. Standard input stream for reading user data.
It is used for input from the keyboard. Standard input stream for reading user data.
← Didn't Know|Knew It →
What is the default value of a boolean variable?
What is the default value of a boolean variable?
Tap to reveal answer
false. Boolean variables automatically initialize to false.
false. Boolean variables automatically initialize to false.
← Didn't Know|Knew It →
What is the output of 'System.out.println(3 * 2 + " apples");'?
What is the output of 'System.out.println(3 * 2 + " apples");'?
Tap to reveal answer
6 apples. Arithmetic is evaluated first, then concatenated with string.
6 apples. Arithmetic is evaluated first, then concatenated with string.
← Didn't Know|Knew It →
Identify the error in 'boolean flag = "true";'
Identify the error in 'boolean flag = "true";'
Tap to reveal answer
Should be: boolean flag = true;. Boolean variables require boolean literals, not strings.
Should be: boolean flag = true;. Boolean variables require boolean literals, not strings.
← Didn't Know|Knew It →
What keyword declares a constant in Java?
What keyword declares a constant in Java?
Tap to reveal answer
The 'final' keyword. Prevents variable value from being changed after initialization.
The 'final' keyword. Prevents variable value from being changed after initialization.
← Didn't Know|Knew It →
What is the result of '5.0 / 2' in Java?
What is the result of '5.0 / 2' in Java?
Tap to reveal answer
2.5. At least one operand is double, so result is double.
2.5. At least one operand is double, so result is double.
← Didn't Know|Knew It →
What symbol is used for comments in Java?
What symbol is used for comments in Java?
Tap to reveal answer
// for single line comments. Text after these symbols is ignored by compiler.
// for single line comments. Text after these symbols is ignored by compiler.
← Didn't Know|Knew It →
What is the output of 'System.out.println(5 == 5);'?
What is the output of 'System.out.println(5 == 5);'?
Tap to reveal answer
true. The equality comparison evaluates to boolean true.
true. The equality comparison evaluates to boolean true.
← Didn't Know|Knew It →
What method reads an integer from Scanner 'sc'?
What method reads an integer from Scanner 'sc'?
Tap to reveal answer
sc.nextInt();. Reads next integer token from input stream.
sc.nextInt();. Reads next integer token from input stream.
← Didn't Know|Knew It →
How do you import the Scanner class in Java?
How do you import the Scanner class in Java?
Tap to reveal answer
import java.util.Scanner;. Required before using Scanner in your program.
import java.util.Scanner;. Required before using Scanner in your program.
← Didn't Know|Knew It →
Identify the error in 'Scanner sc = new Scanner(System.in'
Identify the error in 'Scanner sc = new Scanner(System.in'
Tap to reveal answer
Missing closing parenthesis ')'. Constructor call needs both opening and closing parentheses.
Missing closing parenthesis ')'. Constructor call needs both opening and closing parentheses.
← Didn't Know|Knew It →
What does 'int a = 7;' do?
What does 'int a = 7;' do?
Tap to reveal answer
Declares and initializes 'a' with 7. Creates variable and assigns initial value in one statement.
Declares and initializes 'a' with 7. Creates variable and assigns initial value in one statement.
← Didn't Know|Knew It →
What is the syntax for declaring an integer variable 'a'?
What is the syntax for declaring an integer variable 'a'?
Tap to reveal answer
int a;. Declares variable without assigning a value.
int a;. Declares variable without assigning a value.
← Didn't Know|Knew It →
What is the result of '10 / 3' in integer division?
What is the result of '10 / 3' in integer division?
Tap to reveal answer
The result is 3. Integer division truncates the decimal portion.
The result is 3. Integer division truncates the decimal portion.
← Didn't Know|Knew It →
Find and correct the error: 'int num = "10";'
Find and correct the error: 'int num = "10";'
Tap to reveal answer
Correct: int num = 10;. Cannot assign String literal to int variable.
Correct: int num = 10;. Cannot assign String literal to int variable.
← Didn't Know|Knew It →
Which data type is used for true/false values?
Which data type is used for true/false values?
Tap to reveal answer
The boolean data type. Stores either true or false values in Java.
The boolean data type. Stores either true or false values in Java.
← Didn't Know|Knew It →
What operator is used for assignment in Java?
What operator is used for assignment in Java?
Tap to reveal answer
The equal sign '=' is used for assignment. Not to be confused with $==$ which tests equality.
The equal sign '=' is used for assignment. Not to be confused with $==$ which tests equality.
← Didn't Know|Knew It →
What is an assignment statement in Java?
What is an assignment statement in Java?
Tap to reveal answer
An assignment statement assigns a value to a variable. It stores a value in memory using the $=$ operator.
An assignment statement assigns a value to a variable. It stores a value in memory using the $=$ operator.
← Didn't Know|Knew It →
How to declare a double variable 'd'?
How to declare a double variable 'd'?
Tap to reveal answer
double d;. Declares double-precision floating-point variable.
double d;. Declares double-precision floating-point variable.
← Didn't Know|Knew It →
What is the result of '7 % 3' in Java?
What is the result of '7 % 3' in Java?
Tap to reveal answer
- Modulus operator returns remainder after division.
- Modulus operator returns remainder after division.
← Didn't Know|Knew It →
What is the syntax to declare a char 'c'?
What is the syntax to declare a char 'c'?
Tap to reveal answer
char c;. Declares single character variable.
char c;. Declares single character variable.
← Didn't Know|Knew It →
What is the output of 'System.out.println(3 * 2 + " apples");'?
What is the output of 'System.out.println(3 * 2 + " apples");'?
Tap to reveal answer
6 apples. Arithmetic is evaluated first, then concatenated with string.
6 apples. Arithmetic is evaluated first, then concatenated with string.
← Didn't Know|Knew It →
What is the result of 'Math.pow(2, 3)'?
What is the result of 'Math.pow(2, 3)'?
Tap to reveal answer
8.0. Calculates $2^3$ which equals 8.0.
8.0. Calculates $2^3$ which equals 8.0.
← Didn't Know|Knew It →
How do you import the Scanner class in Java?
How do you import the Scanner class in Java?
Tap to reveal answer
import java.util.Scanner;. Required before using Scanner in your program.
import java.util.Scanner;. Required before using Scanner in your program.
← Didn't Know|Knew It →
What does 'int a = 7;' do?
What does 'int a = 7;' do?
Tap to reveal answer
Declares and initializes 'a' with 7. Creates variable and assigns initial value in one statement.
Declares and initializes 'a' with 7. Creates variable and assigns initial value in one statement.
← Didn't Know|Knew It →
Identify the error in 'Scanner sc = new Scanner(System.in'
Identify the error in 'Scanner sc = new Scanner(System.in'
Tap to reveal answer
Missing closing parenthesis ')'. Constructor call needs both opening and closing parentheses.
Missing closing parenthesis ')'. Constructor call needs both opening and closing parentheses.
← Didn't Know|Knew It →
What symbol is used for comments in Java?
What symbol is used for comments in Java?
Tap to reveal answer
// for single line comments. Text after these symbols is ignored by compiler.
// for single line comments. Text after these symbols is ignored by compiler.
← Didn't Know|Knew It →
Convert the string "123" to an integer.
Convert the string "123" to an integer.
Tap to reveal answer
Integer.parseInt("123");. Converts String representation to int value.
Integer.parseInt("123");. Converts String representation to int value.
← Didn't Know|Knew It →