Font size
WorksheetsIP MIDTERM
Total questions: 45
Worksheet time: 23mins
Which of the following method calls is valid?
c = sum(a, b);
Which of the following method calls is valid?
a = sum(list1[0], list2[0]);
Which of the following method calls is valid?
c = sum(list1, list2);
Which of the following method calls is valid?
for (int i = 1; i <= 10; i++) list3[i] = sum(list1[i], list2[i]);
Which of the following method calls is valid?
b=sum(list1[a],list[b]);
Creating a 1D array of integers and initializing it:
int[] arr = (a) int[]{1, 2, 3, 4, 5};
Creating a 2D array of strings and initializing it:
String (a) arr = new String[][]{
{John, Doe},
{Jane, Doe},
{Bob, Smith}};
Accessing an element of a 1D array by index:
int[] arr = new int[]{1, 2, 3, 4, 5};
int value = arr[ (a) ]; // value will be 3
Accessing an element of a 2D array by row and column index:
String[ ][ ] arr = new String[ ][ ]
{"John", "Doe"},
{"Jane", "Doe"},
{"Bob", "Smith"} };
String value = arr (a) ; // value will be "Jane"
Usage of foreach loop in java
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
for (String i : cars) {
System.out.println( (a) ); //display all the values of cars }
Creating an ArrayList of integers and adding elements to it:
(a) <Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
Creating an ArrayList of strings and adding elements to it:
ArrayList<String> list = new ArrayList<String>();
list.________________("apple");
list.________________("banana");
list.________________("cherry");
(a)
Removing an element from an ArrayList by index:
ArrayList<String> list = new ArrayList<String>();
list.add("apple");
list.add("banana");
list.add("cherry");
list.remove( (a) ); // removes the element at index 1 (banana)
Checking if a String contains a substring:
String str = "Hello, world!";
boolean containsSubstring = str. (a) ("world"); // containsSubstring will be true
Concatenating two strings:
String str1 = "Hello";
String str2 = "world";
String result = (a) + “ “ + str2; // result will be "Hello world”
