OC userin Computer Science·24 May 201821. What prints when the following code executes? public static void main(String[] args) { into a = new int [4] [; mystery (a); System.out.print (a.length + ", "); System.out.println(a [2] .length); public static void mystery (int[][] a) { for (int i=0; i
OC userin Computer Science·22 May 201833. In TCP/IP model, which of the following protocols belong to the application layer? a) File Transfer Protocol (FTP) b) Secure Shell Host (SSH) c) Simple Mail Transfer Protocol (SMTP) d) Hypertext Transfer Protocol (HTTP) e) All of the above x
OC userin Computer Science·22 May 201817. What prints when the following snippet of code is executed? int[] a = {1,2,3}; for (int i = 0; i <= a.length; i++) { System.out.print (i + " ");
OC userin Computer Science·19 May 201852. Line 8 (A) break; } (B) current = current.getNext(); } (C) } (D) return;} (E) return counter;}
OC userin Computer Science·18 May 201816. What does the following program print? int x = 10; void setup() { int 2 times Two (x); println(x); println(z); A. 10, 10, 20 B. 10, 20, 10 c. 10, 20, 20 D. 20, 20, 10 E. 20, 10, 20 int timesTwo (int y) { x = y* 2; println(y); return x;
OC userin Computer Science·15 May 2018Part (c) [2 MARKS] You almost certainly have duplicate code between your two functions. Write a helper function that you could have used to eliminate that duplicate code. Do not rewrite your functions for parts (a) and (b). It is not necessary to write a docstring.
OC userin Computer Science·17 May 201822. What does the following method return when the input array is { 1, 2, 3} ? public static int mystery (int[] array) { int i = 0; int count = 0; while (i <= array.length) { if (array[i] : 2 == 0) { count++; i++; return count; (A) There is a runtime error. (B) 3 (C) There is a compiler error. (D) O (E) 2
OC userin Computer Science·17 May 201833. Base10 is the set of numbers created from the digits {0,1,2,3,4,5,6,7,8,9}. Whereas base2, which is the set of numbers created with {0,1}. We could similarly define base; as the ordered set of characters created from {X,Y,Z}. What is the following basez number, Yxz, in base ? Random graph For this section you will need to look at the classes Graph and GraphNode present in the appendix. A Graph consists of a number of nodes, each of which has connections to other nodes in the graph. You can think of nodes as a representation of a person in a social network (e.g. Facebook). The ArrayList connectedTo variable in GraphNodes is the list of friends that particular person has. For example, in the following graph, the node O is friends with node 1 and 2. On the other hand, node 2 and node 1 are not friends, hence the lack of link. 0-0 In the constructor of the Graph, the process of connecting nodes is randomized. Moreover, we will not allow a node to be connected to itself and we are going to assume that the arguments passed to the Graph constructor respect the following conditions: n > 2, and n > nbConnections. Pay close attention to the character order
OC userin Computer Science·15 May 201810. What does the following program print? // caution - this may be a trick question int[] data = new int[5]; for (int i = 0; i < data.length; i++) { data[i] = 1*2; for (int i = data.length-1; i >= 0; i--) { print (data[i] + " ");
OC userin Computer Science·15 May 201814. In secondary memory, an advantage of using SSDs over HDDs is a resistant to physical shock b. inexpensive c. high capacity of up to about 10TB d. all of the above
OC userin Computer Science·13 May 201833. What is the second value printed by the program to the right? A.-1 B.O C.5 D.7 E.10 void setup() { int[] data = { 7, 10, 3, io, 6, 7, 15, 10, 10 System.out.println(func1(10, data)); System.out.println(func1(7, data)); 1/ look close - this is not quite the // same function as before int funci(int x, int[] data) { for(int i = data.length-1; i >= 0; i--) if (data[i] == x) return i; return -1;
OC userin Computer Science·8 May 201827. In a packet switched computer network which of the following statements is true? a) If a packet is lost or damaged, then the entire message needs to be retransmitted. b) Network devices need to have sufficient memory to store all packets for a given message. c) All packets belonging to the same message must use the same route for a given destination. d) The latency is lower than a message switched network, since the first packet can be sent right away without waiting for other packets to be ready. x e) None of the above
OC userin Computer Science·8 May 2018(d) public class ReferenceTest4 public static void methodFour (int[] x, int[] y) x[0] ++; X = Y; x[0] ++; public static void main(String[] args) { int[] a - {1,2,3}; int[] b - (100, 101, 102); methodFour (a,b); //IS THE DATA STORED OR REFERRED TO BY a THE SAME? (ANSWER IN CHART) //IS THE DATA STORED OR REFERRED TO BY THE SAME? (ANSWER IN CHART)
OC userin Computer Science·6 May 2018Part (b) [3 MARKS] Complete the function body according to its docstring description. You will be marked only on the parts that need to be different from (a). def count_letter_case_mutate (L): " (list of list of str) -> None Type Precondition: each str in L is non-empty and contains only alphabetic characters Replace each item in L with a two-item tuple in which the first item is the number of words in the list at the corresponding index of L that start with a lowercase letter and the second item is the number of words in the list at the corresponding index of L that start with an uppercase letter >>> data = [['apple', 'Banana'], ['PeAr'], [], ['PEACH', 'aprICot', 'plum']] >>> count_letter_case_mutate (data) >>> data [(1, 1), (0, 1), (0, 0), (2, 1)]