AP Computer Science a Flashcards: Assignment Statements And Input

Study Assignment Statements And Input in AP Computer Science a with focused flashcards that help you recognize the idea, recall the key rule, and apply it in practice-style prompts.

AP Computer Science a

Assignment Statements And Input

0 mastered0 still learning

0% Complete

QUESTION
1/ 68

Identify the error in 'boolean flag = "true";'

Tap card or press Space to flip

ANSWER

Should be: boolean flag = true;. Boolean variables require boolean literals, not strings.

How well did you know it?

Card 1 / 68

What this deck covers

This deck focuses on Assignment Statements And Input, giving you a quick way to review the definitions, rules, and examples that matter most for AP Computer Science a.

How to use these flashcards

Work through these flashcards in short sessions. Try to answer each prompt before flipping the card, then revisit any cards you miss until the explanation feels automatic.

All flashcards

Flashcard 1: Identify the error in 'boolean flag = "true";'

Answer: Should be: boolean flag = true;. Boolean variables require boolean literals, not strings.

Flashcard 2: Convert the string "123" to an integer.

Answer: Integer.parseInt("123");. Converts String representation to int value.

Flashcard 3: What is the output of 'System.out.println(3 * 2 + " apples");'?

Answer: 6 apples. Arithmetic is evaluated first, then concatenated with string.

Flashcard 4: Identify the error: 'int a; a = "hello";'

Answer: Cannot assign String to int. String literal cannot be stored in int variable.

Flashcard 5: What is the output of 'System.out.println("5" + 5);'?

Answer:

  1. String concatenation converts int to string first.

Flashcard 6: Which data type is used for true/false values?

Answer: The boolean data type. Stores either true or false values in Java.

Flashcard 7: What does 'int a = 7;' do?

Answer: Declares and initializes 'a' with 7. Creates variable and assigns initial value in one statement.

Flashcard 8: What is the initial value of an int array element?

Answer:

  1. All numeric arrays initialize elements to zero.

Flashcard 9: Find and correct the error: 'int num = "10";'

Answer: Correct: int num = 10;. Cannot assign String literal to int variable.

Flashcard 10: What is the result of 'Math.pow(2, 3)'?

Answer: 8.0. Calculates 232^3 which equals 8.0.

Flashcard 11: What method reads an integer from Scanner 'sc'?

Answer: sc.nextInt();. Reads next integer token from input stream.

Flashcard 12: What keyword declares a constant in Java?

Answer: The 'final' keyword. Prevents variable value from being changed after initialization.

Flashcard 13: What is the syntax for declaring an integer variable 'a'?

Answer: int a;. Declares variable without assigning a value.

Flashcard 14: What is an assignment statement in Java?

Answer: An assignment statement assigns a value to a variable. It stores a value in memory using the == operator.

Flashcard 15: What is the result of '10 / 3' in integer division?

Answer: The result is 3. Integer division truncates the decimal portion.

Flashcard 16: Convert the string "123" to an integer.

Answer: Integer.parseInt("123");. Converts String representation to int value.

Flashcard 17: What is the result of '5.0 / 2' in Java?

Answer: 2.5. At least one operand is double, so result is double.

Flashcard 18: Which data type is used for true/false values?

Answer: The boolean data type. Stores either true or false values in Java.

Flashcard 19: How do you import the Scanner class in Java?

Answer: import java.util.Scanner;. Required before using Scanner in your program.

Flashcard 20: What is the purpose of 'System.in'?

Answer: It is used for input from the keyboard. Standard input stream for reading user data.

Flashcard 21: What is the default value of a boolean variable?

Answer: false. Boolean variables automatically initialize to false.

Flashcard 22: What keyword declares a constant in Java?

Answer: The 'final' keyword. Prevents variable value from being changed after initialization.

Flashcard 23: What is the output of 'System.out.println(5 == 5);'?

Answer: true. The equality comparison evaluates to boolean true.

Flashcard 24: What is the result of '5.0 / 2' in Java?

Answer: 2.5. At least one operand is double, so result is double.

Flashcard 25: What is the result of '10 / 3' in integer division?

Answer: The result is 3. Integer division truncates the decimal portion.

Flashcard 26: What is the syntax to declare a char 'c'?

Answer: char c;. Declares single character variable.

Flashcard 27: What operator is used for assignment in Java?

Answer: The equal sign '=' is used for assignment. Not to be confused with ==== which tests equality.

Flashcard 28: Identify the error: 'int a; a = "hello";'

Answer: Cannot assign String to int. String literal cannot be stored in int variable.

Flashcard 29: What method reads a line of text in Scanner 'sc'?

Answer: sc.nextLine();. Reads entire line including spaces until newline.

Flashcard 30: What is the result of 'Math.pow(2, 3)'?

Answer: 8.0. Calculates 232^3 which equals 8.0.

Flashcard 31: Which operator checks equality in Java?

Answer: The '==' operator. Compares values for equality, returns boolean.

Flashcard 32: What method reads a line of text in Scanner 'sc'?

Answer: sc.nextLine();. Reads entire line including spaces until newline.

Flashcard 33: What is the output of 'System.out.println(2 + "3");'?

Answer:

  1. String concatenation occurs when adding to String.

Flashcard 34: Which method is used to read a double from Scanner 'sc'?

Answer: sc.nextDouble();. Reads floating-point number from input stream.

Flashcard 35: What is the purpose of 'System.in'?

Answer: It is used for input from the keyboard. Standard input stream for reading user data.

Flashcard 36: What operator is used for assignment in Java?

Answer: The equal sign '=' is used for assignment. Not to be confused with ==== which tests equality.

Flashcard 37: What is the syntax to declare a float 'f'?

Answer: float f;. Declares floating-point variable without initialization.

Flashcard 38: What is the output of 'System.out.println(5 == 5);'?

Answer: true. The equality comparison evaluates to boolean true.

Flashcard 39: What is the output of 'System.out.println(5 / 2);'?

Answer:

  1. Integer division discards fractional part of result.

Flashcard 40: What is the default value of a boolean variable?

Answer: false. Boolean variables automatically initialize to false.

Flashcard 41: What does 'int a = 7;' do?

Answer: Declares and initializes 'a' with 7. Creates variable and assigns initial value in one statement.

Flashcard 42: Identify the error in 'Scanner sc = new Scanner(System.in'

Answer: Missing closing parenthesis ')'. Constructor call needs both opening and closing parentheses.

Flashcard 43: How to declare a double variable 'd'?

Answer: double d;. Declares double-precision floating-point variable.

Flashcard 44: What symbol is used for comments in Java?

Answer: // for single line comments. Text after these symbols is ignored by compiler.

Flashcard 45: What is the output of 'System.out.println(3.0 * 2);'?

Answer: 6.0. Double operand makes result a double value.

Flashcard 46: Which operator checks equality in Java?

Answer: The '==' operator. Compares values for equality, returns boolean.

Flashcard 47: What is an assignment statement in Java?

Answer: An assignment statement assigns a value to a variable. It stores a value in memory using the == operator.

Flashcard 48: What is the output of 'System.out.println(2 + "3");'?

Answer:

  1. String concatenation occurs when adding to String.

Flashcard 49: What symbol is used for comments in Java?

Answer: // for single line comments. Text after these symbols is ignored by compiler.

Flashcard 50: What is the syntax to declare a float 'f'?

Answer: float f;. Declares floating-point variable without initialization.

Flashcard 51: What is the syntax for initializing a String 's'?

Answer: String s = "Hello";. String literals are enclosed in double quotes.

Flashcard 52: What method reads an integer from Scanner 'sc'?

Answer: sc.nextInt();. Reads next integer token from input stream.

Flashcard 53: What is the initial value of an int array element?

Answer:

  1. All numeric arrays initialize elements to zero.

Flashcard 54: What is the output of 'System.out.println(3 * 2 + " apples");'?

Answer: 6 apples. Arithmetic is evaluated first, then concatenated with string.

Flashcard 55: Find and correct the error: 'int num = "10";'

Answer: Correct: int num = 10;. Cannot assign String literal to int variable.

Flashcard 56: How do you import the Scanner class in Java?

Answer: import java.util.Scanner;. Required before using Scanner in your program.

Flashcard 57: What is the syntax for initializing a String 's'?

Answer: String s = "Hello";. String literals are enclosed in double quotes.

Flashcard 58: What is the syntax for declaring an integer variable 'a'?

Answer: int a;. Declares variable without assigning a value.

Flashcard 59: What is the result of '7 % 3' in Java?

Answer:

  1. Modulus operator returns remainder after division.

Flashcard 60: What is the output of 'System.out.println(3.0 * 2);'?

Answer: 6.0. Double operand makes result a double value.

Flashcard 61: What is the result of '7 % 3' in Java?

Answer:

  1. Modulus operator returns remainder after division.

Flashcard 62: What is the output of 'System.out.println("5" + 5);'?

Answer:

  1. String concatenation converts int to string first.

Flashcard 63: Which method is used to read a double from Scanner 'sc'?

Answer: sc.nextDouble();. Reads floating-point number from input stream.

Flashcard 64: Identify the error in 'Scanner sc = new Scanner(System.in'

Answer: Missing closing parenthesis ')'. Constructor call needs both opening and closing parentheses.

Flashcard 65: Identify the error in 'boolean flag = "true";'

Answer: Should be: boolean flag = true;. Boolean variables require boolean literals, not strings.

Flashcard 66: What is the syntax to declare a char 'c'?

Answer: char c;. Declares single character variable.

Flashcard 67: What is the output of 'System.out.println(5 / 2);'?

Answer:

  1. Integer division discards fractional part of result.

Flashcard 68: How to declare a double variable 'd'?

Answer: double d;. Declares double-precision floating-point variable.