Test
Multiple Choice CSC110 Questions
Crea una cuenta gratis para terminar este test
Guarda tu progreso y consulta tu resultado final.
¿Ya tienes cuenta? Inicia sesión
Preguntas del test (22)
1What is the primary purpose of a complier?
- Ato allow programmers to edit program code
- Bto run programs that have been written earlier
- Cto translate high-level program code into instructions that can be executed
- Dto check programs for logical errors
2System.out.println(9 + ("8" + 7) + "6" + 5 * 4 + (3 + 2) + 1);
- A9"8"7"6"2051
- B91562051
- C98762051
- D56
3System.out.println( "/\this is a \"/total/\" \\mystery!/" );
- A/this is a " otal/" \\mystery!
- B/\this is a " otal\" \mystery!"
- Cthis is a /total mystery!/
- D/ his is a "/total/" \mystery!/
4System.out.println ( (int) 3.0 - 5 /3 * 1.5);
- A1.5
- B1
- C1.0
- D0
5String message = "Jens Weber";
int i = message.indexOf("W");
System.out.println(message.substring(i, i+4));- AJens
- BWebe
- Ceber
- D6
6System.out.println(15 % 5);
- A0
- B1
- C3
- D3.0
7int times = 4;
for (int i = 1; i <= times; times++) {
System.out.println("Shouting Hooray! " + i);
}
System.out.println("Finished shouting " + times + "times");
What of the following best describes an error in the above code?- AThe for-loop declaration is incorrect
- BThe for-loop repeats infinitely
- CYou cannot print text and a variable in a println statement
- Dtimes is out of scope in the final println statement
8int price;
double price_with_tax = price * 1.15;
System.out.println("The price including tax is " + price_with_tax);
Which of the following describes an error in the above code?- AAn int cannot be multiplied with a double
- Bprice_with_tax is not a valid identifier
- CVariable price has not bee initialized
- DYou cannot print text and a variable in a println statement
9public static void methodA (int a, int b) {
int y = 3 * b;
methodB(a-3, b, y);
}
public static void methodB(int x, int y, int z) {
z = x- y;
System.out.println(z + " minus " + x + " equals " + y);
}
What is the output of the following statements:
int x = 2;
int y = 3;
methodB(y, x, 4);- A-1 minus 2 equals 3
- B1 minus 3 equals 2
- C4 minus 3 equals 2
- D4 minus 2 equals 3
10public static void methodA (int a, int b) {
int y = 3 * b;
methodB(a-3, b, y);
}
public static void methodB(int x, int y, int z) {
z = x- y;
System.out.println(z + " minus " + x + " equals " + y);
}
What is the output of the following statements:
int a = 7;
methodA(5, a);- A2 minus 21 equals 4
- B-3 minus 4 equals 7
- C-5 minus 2 equals 7
- D7 minus 4 equals 21
11The code above will NOT compile. Which of the following describes a reason for this:
- AA string array cannot be printed with println
- BA method cannot return an array
- CVariable n (in method readTAs) is not initialized
- DThe + operator does not work on arrays
12Ignoring the above compilation error, which of the following best describes a logical error in the above code?
- AA method cannot return one of its parameters as a return value
- BString values cannot be compared with !=
- CThe loop should be a definitive loop (for loop)
- DThe condition of the while loop should be while(input.hasNext())
13Which logical error exists with respect to the file handling?
- ACourseTeam.txt is not a valid path
- BThe file CourseTeam.txt may already exist and cause an exception
- CThe content of an array cannot be written to the file by passing it to out.println
- DThe file CourseTeam.txt may not exist and cause an exception
14Which of the following is true about class constants?
- AClass constant are in scope of all methods within a class
- BClass constants must be defined at the beginning of a class file
- CThe value of class constants can be redefined in static methods
- DClass constants cannot be used as return values in methods
15public static void ifElseMethod(int x, int y) {
if (x < y) {
x = x + 5;
}
else if ( y < 3 * x) {
y = 7;
}
if (x <= 4 || y < x) {
x = x - 3;
y = y + 5;
}
System.out.println(x + " " y);
}
What is the output of the following statement: ifElseMethod(3, 8);- A3 7
- B8 8
- C0 13
- D5 13
16public static void ifElseMethod(int x, int y) {
if (x < y) {
x = x + 5;
}
else if ( y < 3 * x) {
y = 7;
}
if (x <= 4 || y < x) {
x = x - 3;
y = y + 5;
}
System.out.println(x + " " y);
}
What is the output of the following statement: ifElseMethod(9, 4);- A6 12
- B14 9
- C10 7
- D10 16
17Which of the following is not true about constructors in java?
- AConstructors can have parameters
- BConstructors can have return values
- CA class can have multiple constructors
- DConstructors must have the same name as the class they are defined in
18int[] x = {8, 3, 6, 1, 4};
int[] y = new int[5];
x[2] = y[3];
y = x;
y[2] = x[3];
What are the values stored in arrays x and y after executing the following code?- Ax: {8, 3, 1, 1, 4}, y:{8, 3, 1, 1, 4}
- Bx: {8, 3, 0, 1, 4}, y: {8, 3, 1, 1, 4}
- Cx: {8, 0, 6, 1, 4}, y: {8, 0, 6, 1, 4}
- Dx: {8, 0, 6, 1, 4}, y: {8, 6, ,6 ,1, 4}
19public static void readFile(String fileName) throws
FileNotFoundExeception {
File theFile = new File(fileName);
Scanner scan = new Scanner(theFile);
int sum = 0;
int num = 0;
while (scan.hasNext()) {
num = scan.nextInt();
sum += num;
}
System.out.println("Sum is " + sum);
}
This file is in the directory: numbers.txt and contains 3 9 1 7
What is the output of the following statement: readFile("numbers.txt");- ASum is 3917
- BSum is 20
- CSum is 7
- DNone of the above
20public static void readFile(String fileName) throws
FileNotFoundExeception {
File theFile = new File(fileName);
Scanner scan = new Scanner(theFile);
int sum = 0;
int num = 0;
while (scan.hasNext()) {
num = scan.nextInt();
sum += num;
}
System.out.println("Sum is " + sum);
}
This file is in the directory input.txt and contains: 8 5 avg 4
What is the output of the following statement: readFile("input.txt");- ASum is 85avg4
- BSum is 17
- CSum is 13
- DNone of the above
21What is sequential sort?
- ATakes a sequence and swaps each element if the one next to it is smaller then the other
- BLocates a target value in an array by examining each element from start to finish
- CDivides an array into smaller arrays, then sorts
- DNone of the above
22What is binary search?
- ALocates a value in a sorted array by successively eliminating half of the array from consideration
- BSorts an array by swapping elements
- CLocates a value in an array by making the array into smaller arrays to be sorted
- DNone of the above
Información
- Descripción
- Computer Science Test sobre Multiple Choice CSC110 Questions, creado por Tess Greenlay el 13/12/2017.
- Autor
- Tess Greenlay
- Idioma
- English
- Visitas
- 12
- Etiquetas
- Valoración
- Aún sin valoraciones Valora este test