1/36
Looks like no tags are added yet.
What is an algorithm?
A process that defines step-by-step instructions for completing a task
In programming, what does sequencing determine?
The order in which steps are executed
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
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.
A runtime error typically causes a program to:
stop abnormally during execution.
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
HSWhat 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.
Which of the following correctly creates a Scanner object
Scanner input = new Scanner(System.in);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();
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
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
What will this expression evauluate to?
(int) 9.9
9
What is the value of the following expression?
(int) 2.5 * 2 4
What is the value of the following expression?
(int) (2.75 - 0.5)2
What is the output of the following code segment?
int x = 9;
double y = x;
System.out.println(y);9.0;
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
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
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);
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
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
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
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
What is the role of Java libraries in programming?
To provide prewritten code for reuse, saving time and effort
What is a java package
A collection of related classes grouped together
What does an API documentation provide?
Instructions on how to use classes and methods in libraries
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
Good programmers use comments to?
Make their code mroe readable by explaining particular chunks of code
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
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
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
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
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
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
What is the primary motivation of creating a custom method in a program?
To break down complex problems into smaller, reusable pieces of code
Which of the following method signatures correctly includes a parameter?
public static void methodName(String name)
Which of the following method signatures will correctly return an integer when called upon?
public static int mystery(int number)
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.
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.