Programming

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which of the following is used in conjunction with the equals '=' sign to check if two primitive values are not equal?

!

Which of the following shows the correct syntax for the AND operator?

&&

Which of these is the operator that provides a shorthand way of appending a string?

+=

If ArrayList's indexOf method is called, with a value that does not exist in the arraylist, what is returned?

-1

What, if anything, is the value of x given the following code? String word = "Programming"; var x = word.indexOf('u');

-1

Consider the following code. public static void main(String[] args) { ArrayList list = new ArrayList(); list.add(3); list.add(2); list.add(1); list.add(0); deleteEntry(list,2); System.out.println(list.get(2)); } static void deleteEntry(ArrayList list, int index){ list.remove(index); } What is output when the main method is executed?

0

How many times would the loop below iterate? for (int n = 32; n < 55; n += 2) {

12

Consider the following code where 'located' is a boolean set to 'false' int credits = 0; if (!located) { credits = 15; } System.out.println(credits); What, if anything, would be output to the console?

15

Without executing the code, determine the value of x output to the console given the code below? int x = 5; for (int i = 0; i < 2; i++) { for (int j = 1; j < 4; j++) { x *= j; } } System.out.println(x);

180

Without executing the code, determine the value of x output to the console given the code below? int x = 1; for (int i = 2; i < 7; i++) { x = x + i; } System.out.println(x);

21

What is the value output to the console if the code below was executed? Q) int[][] twoDimensionalIntArray = {{1,2,3},{4,5,6},{7,8,9}}; int someValue = twoDimensionalIntArray[2].length; System.out.println(someValue);

3

Consider the following code, where 'member' is a boolean set to 'true': if (member) { int customerCode = 32; } System.out.println(customerCode); What, if anything, would be printed to the console?

32

How many bits does Java use to store an int value?

32

What is the value of x printed to the console, given the code below? int x = 2; for (int i = 0; i < 5; i++) { x = i; } System.out.println(x);

4

What value would be output to the console if the following code was executed? int[][] twoDimensionalIntArray = {{1,2},{5,6},{9,10},{13,14}}; int someValue = twoDimensionalIntArray.length; System.out.println(someValue);

4

How many times would the below loop iterate? for (int p = 20; p >= 5; p -= 3) {

6

Given the code below, what is the highest index that could be used to access an item in the array? String[] words = new String[9];

8

Given the following code, how many times would X be printed? String[][] stringArray = new String[2][3]; for (int i = 0; i < stringArray.length; i++) { System.out.println('X'); for (int j = 0; j < stringArray[i].length; j++) { System.out.println('X'); } }

8

Q) What would the value of x be at the end of the final iteration, but before the loop exits? for (int i = 0; i < 10; i++) { int x = 6; x += 2; }

8

What is the value output to the console when the code below is executed? int[][] twoDimensionalIntArray = {{1,2,3},{4,5,6},{7,8,9}}; System.out.println(twoDimensionalIntArray[2][1]);

8

Which of these indicates the order of the parameters to be passed into the assertEquals method in JUnit to ensure the output messages are correct?

<Description of Condition>,<Expected result>,<Actual result>

Which of these is used to check for equality of primitive data types in Java?

==

Consider the following code, where 'member' is a boolean set to 'true': if (member) { int customerCode = 32; } System.out.println(customerCode); What, if anything, would be printed to the console?

A Nothing - the programme would crash

Consider the following code where 'located' is a boolean set to 'false' int credits = 0; if (!located) { credits = 15; } System.out.println(credits); What, if anything, would be output to the console?

A) 15

Consider the following code, where productCode is an integer with the value 2. switch (productCode) { case 1: System.out.println("Left handed screwdriver"); case 2: System.out.println("Tartan Paint"); case 3: System.out.println("Long stand"); } Q) What is output when the code is executed?

A) Tartan Paint Long stand

Which of the following would not be an acceptable method declaration?

A) public static void doWork(int number, void thing) {

When reading text files using the Scanner, and using a method other than nextLine(), which character is used, by default, to separate tokens (tokens are each individual item that the scanner gets)?

All of the below: a. Spaces (e.g. " ") b. New lines (e.g. "\n" ) c. Carriage return (e.g. "\r" )

Which of the following methods belong to the class that allows us to check values returned by methods are as expected?

All of the below: assertEquals assertFalse assertNull

Which of the following is true?

An ArrayList may be created with an initial capacity

Which of the following errors is thrown if an attempt is made to access an item at a position beyond the final index of an Array in Java?

ArrayIndexOutOfBoundsException

Which of the following set of statements is true

Arrays can hold primitive and object types ArrayLists can hold only object types

What is the name of the class used when testing with JUnit, that is used to verify that values are as expected?

Assert

Given an array named myArray, consider this syntax: myArray[2] Which of the following statements is true?

Both below are true: a. The syntax could be used, as part of a complete line of code, to retrieve an item in the array b. The syntax could be used, as part of a complete line of code, to set the value of an item in the array

Which keyword is used to completely exit a loop?

Break

The code below shows a method declaration and a call to that method. public static int doSomething(int number){ return "'"+number+"'"; } String x = doSomething(5); There is an error. Which of the following single changes could resolve the error

Change method's return type

The primitive type char has a corresponding Class. What is it called?

Character

A developer writes a programme, however it does not run when the developer clicks the 'run' button. What type of error is most likely to have occured?

Compilation error

Q) Which of the following keywords can be used to exit the current iteration of the loop, and jump straight to the next iteration?

Continue

In Java, a boolean value represents

Either true or false

If a user were to delete a file that the Scanner was to use, then an error would occur. What is the formal name for an error of this kind?

Exception

A Java 'for each' loop provides access to the index value of each item in the array as it is iterating

False

Iterators work with standard Arrays as well as ArrayLists

False

The name of a variable passed into a method must match the name of the corresponding parameter in the method declaration

False

Which keyword is used to define a variable as being constant (i.e. never changing)?

Final

In a Java Switch statement, when is code in the default clause executed?

If either no other clause has been met, or a preceding clause has been met, and there was no break statement in between the preceding clause and the default clause.

The code inside an 'else' block is executed

If the condition tested by the corresponding 'if' statement evaluates to false

The primitive data type 'int' has a corresponding class. How is this class named?

Integer

Which of these statements applies to a 'do-while' loop, but not to a 'while' loop?

It is guaranteed that code within the loop will run at least once

Which of these is a property of a Java Array that gives the number of items in the array?

Length

Which of the following is not a Java Unit testing framework?

Moq

In Java, what is the preset order in which calculations are completed?

Multiplication, division and modulo operations, followed by addition and subtraction

Q) In the code below i is accessible outside the loop for (int i = 0; i < 10; i++) {

No, it's not

In a Java Switch statement, when is code in the default clause executed?

Only when no other condition is met

The default behaviour of Files.write() is to

Overwrite any existing file with the same name

If a 'while' loop is used with a variable to keep count of the number of times it has iterated, it must be declared when?

Prior to, and outside, the loop syntax

What is the effect of String's trim() method?

Removes all spaces from the start and end of the String

Which of these is used to create a new instance of the Scanner?

Scanner consoleScanner = new Scanner(System.in);

Which of the following shows the correct way to access an item with an index of 4 in an ArrayList of Strings called list?

String x = list.get(4);

A method, to be tested, returns an int value. Which of the following statements is true in regards to unit testing the method with JUnit?

The expected value and actual value should be compared using assertEquals because this method provides more helpful information in the output window if the test fails.

If a piece of code, intended to read a file from disk using a Scanner, is not placed in a try-catch block, what would happen if it could not read the file due to it having been moved by the user?

The programme will crash

What, if any, type of error would the following code result in? String prodCode = "N1827"; char prefix = prodCode.charAt(0); prefix += 2; System.out.println(prefix);

There is no error

A programmer may specify a specific character that should be used to separate tokens in a text file being read by the scanner

True

Once instantiated, Java Arrays have a fixed size

True

The code shown here is valid int[][][] someArray = {{{1},{2}},{{3},{4}}};

True

The type of a variable passed into a method must match the type of the corresponding parameter in the method declaration

True

double stores values more accurately than float

True

In the code below x would not be accessible outside the loop for (int i = 0; i < 10; i++) { int x = x + i;

True. It not accessible outside the loop

Which of the following lists all the safe ways to delete an items in an arraylist whilst looping through it

Using an iterator

How can the contents of an ArrayList be most easily placed in a standard Array?

Using the ArrayList's toArray() method

Which of the following set of statements is true?

Variables declared outside a loop can be accessed inside the loop Variables declared inside a loop cannot be accessed outside the loop

Which of the following is the correct type for a method that does not return a value

Void

What is the output of the following code? int counter = 2; do { counter++; System.out.println("x"); } while (counter < 6);

XXXX

boolean a = true; boolean b = false; boolean c = true; if (!b || !c) { System.out.print("x"); } else{ System.out.print("y"); } if (c){ System.out.print("z"); } What would be output if the code was executed?

Xz

Can a method omit a return statement?

Yes, when a method's return type is void

Which of the following methods is not available in the JUnit class that allows us to check values returned from methods are as expected?

assertGreaterThan

Which of the following is the correct way to get the number of items in an ArrayList called carsList?

carsList.size()

Given the following code char[][] charArray = {{'a','b'},{'b','c'},{'d','e'}}; Which of the following would access the character 'e'?

charArray[2][1];

What, if any, type of error would the code below result in? String name = "Andrew"; char initial = name.toLowerCase().charAt(0) System.out.println(initial);

compilation

Which of the following would be the value of x, given the following code? String letters = "abcdefgh"; int x = letters.charAt(3);

d

Which of the following data types cannot be switched upon?

double

Which of these is the correct way to compare strings for equality?

equals()

Which of the following shows an example of a valid 'for each' loop, given an array named bookArray?

for (String bookTitle: bookArray) {

Given the following code, what would the value of the variable 'vowel' be? char[] vowels = {'a','e','i','o','u'}; char vowel = vowels[2];

i

The code inside an 'else' block is executed

if the condition tested by the corresponding 'if' statement evaluates to false

Which single import statement could be used instead of the ones shown here: import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.Files;

import java.nio.file.*

Which of these do we include at the top of a file to use the Scanner without it's full name

import java.util.Scanner;

In which order do the statements in a 'for' loop appear?

initialisation statement, continue condition, increment statement

Which of these shows the correct syntax for instantiating an array in Java using an array literal?

int[] myArray = {1,2,3}

Which of the following pieces of code would result in a runtime error?

int[] myArray = {4,8,15,16,23,42}; int last = myArray[6];

Which, if any, of the method names shown below, would locate the position of the final 'ri' in 'piri-piri'?

lastIndexOf()

Which is the correct method name for one which returns the number of characters in the string?

length()

Which of the following demonstrates the correct way to call a method that takes two parameters?

processData(3,6);

Q) user calls a method with the following syntax: doSomething(3,"Hello"); Which of the following could represent the Java method signature for the method they are calling?

public static void doSomething(int number, String text) {

The process of making improvements to code, without changing its intended function (for example by extracting code from a larger method and placing it in it's own carefully named method) is known as what?

refactoring

Which of the following lines of code could be added to the following method to make it semantically and syntactically correct? public static double someMethod(){ int a = 5; double b = 5.0; String c = "5"; char d = '5'; }

return b

Given the code below, what is x? int x = 9/6;

x = 1

Which of the following expression evaluates if x is greater than y

x > y

Which of the following shows the correct syntax for the logical OR operator in Java?

||


Kaugnay na mga set ng pag-aaral

Difference between Par and No Par Value Stock

View Set

Translation: from Nucleic Acid to Amino Acid

View Set

ECON 1000-Ch. 16 and 17- Study Module and Homework Questions

View Set

Medical Terminology for Health Professions 8th Edition, Chapter 1, Learning Exercises

View Set

College Western Civilization 1: Chapter Test: 3

View Set

Horizontal and Vertical Lines, slope, Linear Equations, Linear Equations

View Set