APCSA Units 1.1-1.9 Review

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/36

encourage image

There's no tags or description

Looks like no tags are added yet.

37 Terms

1
New cards


What is an algorithm?

A process that defines step-by-step instructions for completing a task

2
New cards

In programming, what does sequencing determine?

The order in which steps are executed


3
New cards

Which of the following are true about an Integrated Development Environment (IDE)?

I. An IDE provides tools to write, compile, and run code in one place.
II. An IDE is the only place where code can be written.
III. An IDE often includes debugging tools to help identify and fix errors in code.

I and III

4
New cards

Which of the following describes a logic error

? A mistake in the program's logic that produces incorrect results despite the code running without errors.

5
New cards

A runtime error typically causes a program to:

stop abnormally during execution.

6
New cards

Consider the following code segment:

System.out.println("Code"); 

System.out.println("HS");

The code segment is intended to produce the following output but may not work as intended.

Code

HS

What change, if any, can be made so that the code segment produces the intended output?

the statement System.out.println(); should be inserted between the two print statements.

7
New cards


Which of the following correctly creates a Scanner object



	Scanner input = new Scanner(System.in);


8
New cards

What is the correct line of code needed to request a whole number from a user?

Assume a Scanner object called input has already been created.

int num = input.nextInt();

9
New cards


Assume a Scanner object called input has already been correctly declared and initialized.

When the program runs, the user inputs the following values in this order: 5, 10.

System.out.println("Length: ");
double l = input.nextDouble();
System.out.println("Width: ");
double w = input.nextDouble();

double area = l * w;
System.out.print(area);



50.0

10
New cards

Consider the code segment below. Assume a Scanner object called input has already been correctly declared and initialized.

System.out.print("Enter your age: ");
int age = input.nextInt();

System.out.print("Enter your name: ");
String name = input.nextLine();

System.out.print("Hello, ");
System.out.print(name);
System.out.print(". You are ");
System.out.print(age);
System.out.println(" years old.");

What is the result when this code segment is run and the user inputs the following: 25, Charlotte

Hello, . You are 25 years old

11
New cards

What will this expression evauluate to?

(int) 9.9

9

12
New cards

What is the value of the following expression?

(int) 2.5 * 2	


4

13
New cards


What is the value of the following expression?

(int) (2.75 - 0.5)



2

14
New cards

What is the output of the following code segment?

int x = 9;
double y = x;
System.out.println(y);


9.0;

15
New cards

Consider the following code segment:

double x = 2.5;
int y = (int) x * 3;
System.out.print(y);

What is printed as a result of executing the code segment?

6

16
New cards

Consider the following code segment:

int x = 2;
int y = 7;
double result = y / (double) x;
System.out.println(result);

What will be printed when this code is run?

3.5

17
New cards

The following code segment is intended to round num1 to the nearest integer and print the result.

double num1 = 34.6;
/* missing code */
System.out.println(roundedNum1);

What code can be used to replace /* missing code */ so that the code segment works as intended?

int roundedNum1 = (int) (num1 + 0.5);

18
New cards


What will be the output of the following code snippet?

public static void main(String[] args)
{
    int num = 2; 
    int dividend = 5;
    dividend /= num; 
    System.out.println(dividend);    
}



2

19
New cards

What will be stored in the variable modulo after running the following code snippet?

public static void main(String[] args)
{
     int num = 2; 
     int modulo = 15; 
     modulo %= num; 
}


1

20
New cards


What will be stored in the variable age after this code snippet executes?

public static void main(String[] args)
{
    int age = 16;
    age++;
    age--;
    age++;
}



17

21
New cards

Which of the following code segments will end with num holding the value 8?

I.

int num = 4;
num *= 2;
num--;
num++;

II.

int num = 35;
num /= 4; 
System.out.println(num);

III.

int num = 17;
num %= 9;
System.out.println(num);


ALl of the above

22
New cards


What is the role of Java libraries in programming?

To provide prewritten code for reuse, saving time and effort

23
New cards

What is a java package

A collection of related classes grouped together

24
New cards

What does an API documentation provide?

Instructions on how to use classes and methods in libraries

25
New cards


Which of the options below is an advantage of using prewritten classes from libraries in your program?

I) Improves code reliability and efficiency
II) Allows developers to focus on writing unique program features
III) Eliminates the need for testing in programs

Options I and II

26
New cards

Good programmers use comments to?

Make their code mroe readable by explaining particular chunks of code

27
New cards

What is the output of the following code snippet?

int x = 8;
int y = 10;

// x = y + 10;

y *=  2;

/*
y = x;
x *= 3;
*/

System.out.println(x);
System.out.println(y);


8

20

28
New cards


Which comment is most effective for describing the following line of code?

int area = length * width;


//Calculate the area of a rectangle using length and width

29
New cards

How might a programmer use comments to help debug a program?

Comment out a block of code to temporarily disable it and test the program without that part

30
New cards

What is the primary purpose of a Javadoc comment?

To describe the functionality of classes and methods in a format that can generate external documentation

31
New cards

The purpose of specifying a precondition is to?

describe what must be true prior to the execution of the method in order for it to be have as expected

32
New cards

The purpose of specifying a postcondition is to?

explain the method’s end result, whether it is a return value or change in an object’s state

33
New cards

What is the primary motivation of creating a custom method in a program?

To break down complex problems into smaller, reusable pieces of code

34
New cards


Which of the following method signatures correctly includes a parameter?

public static void methodName(String name)


35
New cards


Which of the following method signatures will correctly return an integer when called upon?


public static int mystery(int number)


36
New cards

Which statement best explains the difference between calling a method and defining a method?

Defining a method specifies what the method does, while calling a method executes the instructions in the method.

37
New cards

Consider the following class:

public class Calculator
{
    public static void main(String[] args)
    {
        int firstNum = 5;
        int secondNum = 7;

        int sum = add(firstNum, secondNum);
        System.out.println("Sum: " + sum);
    }

    public static int add(int x, int y)
    {
        return x + y;
    }
}


In the add method header, x and y are parameters, while in the call add(firstNum, secondNum) the variables firstNum and secondNum are arguments.