There are multiple ways this can be done. From the list below, select all of the correct ways to create and initialize A.
int [] A = new int [size];
A[0] = 4;
A[1] = 5;
A[2] = 6;
A[3] = 7;
A[0] = 4;
A[1] = 5;
A[2] = 6;
A[3] = 7;
int [] A = new int [size];
A = {4, 5, 6, 7};
A = {4, 5, 6, 7};
2. Choose the correct ans to initialize an Integer object named num with the value 225.
3. Given this ArrayList declaration of lastNames:
ArrayList <String> lastNames = new ArrayList<>();
lastNames.add("Peter");
lastNames.add("Karter");
lastNames.add("Larry");
What operation(s) would we perform to replace "Peter" with "Meter"?
Answers are
Q1)
Correct Method to create and initialize A are Options A,B
Others option are not correct
Q2)
Answer is Option D
Integer num = new Integer(255) is to initialize an Integer Object
Q3)
Answer is Option A
To replace existing element of Array List in Java. We use Set () method And Set method take two arguments first is the index and second is the new value that you want to insert
So lastNames.set(0, "Meter"); is Correct
These are the Solution for the given problems
If u like the answer then Upvote it and have any doubt comment it
We want to create and then initialize an array named A to contain the integers: 4,...
1.The following statement gets an element from position 4 in an array named myArray: x = myArray[4]; What is the equivalent operation using an array list named list.? A x = list.get(); B x = list.get(4); C x = list.get[4]; D x = list[4]; 2.Consider the following code snippet: ArrayList<Integer> num1 = new ArrayList<Integer>(); int data; Scanner in = new Scanner(System.in); for (int i = 0; i < 5; i++) { data = in.nextInt(); num1.add(data); if (data == 0 &&...
A java exercise please! Write a static method named swapHavles that takes an ArrayList of integers as a a parameter and returns a new ArrayList that has every element in the second half of the original ArrayList swapped with every element in the first half of the original ArrayList. Note: • You can assume that the ArrayList passed to this method as a parameter always contains an even number of elements and will always contain at least two elements. For...
In Java create an integer array named dice1 with a size of 10. Populate each array location with a roll of a six-sided die (hint: an int value of 1 through 6). Print the array out using an enhanced for loop. Sample output: Question 1 dice1 = 1 1 6 2 3 5 1 5 4 5
C# 1.) Assume an integer array named bArray was dimensioned to store 10 rows and 2 columns. Use a variable named element to reference individual cells. Fill in the blanks below for the foreach loop which might be used to display the contents of the array. foreach(Blank 1, Blank 2, Blank 3, Blank 4) . 2.) In order to place a new element in an ArrayList use the ___________ method. 3.) With the following declaration: int [ , ] ctn...
C++ pointers and linked lists 1. Declare an integer pointer variable intPointer. Initialize it to point to an int variable named someInt. Assign the value 451 to someInt and output (cout) the variable someInt and output (cout) the value pointed to by intPointer. Write an assignment statement that indirectly stores 900 into the value pointed to by intPointer. Output (cout) the value pointed to by intPointer and output (cout) the variable someInt, 2. Declare a pointer variable charArrPointer and initialize...
I want to sort my array by pushing the findMax number to the end of the list with this idea The Idea of sort the arraylist: (assume that the arraylist has n elements)Search the n elements of the arraylist for the maximum value then put this maximum value at the last position of the arraylist. Hence at index n-1. Move all other elements forward. Search the first n- 1 elements of the arraylist for the maximum value then put this...
JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a parameter. This method calculates and returns the largest even number in the list. If there are no even numbers in the array, the method should return 0. You can assume that the array is not empty. For example: Test Result int[] values = {1, 4, 5, 9}; System.out.println(getMaxEven(values)); 4 System.out.println(getMaxEven(new int[]{1, 3, 5, 9})); 0 public static int --------------------------------------------------------------------------------- 2. Write a static method...
SQL Create an access database named student11. Create a table named student12 and insert the following records in it. ID StudentName Grade 1 John 90 2 Jim 70 3 Larry 85 4 Sally 20 5 Sam 60 6 Sandra 100 7 Runa 55 8 Simran 35 9 Seema 65 10 Ramu 75 Create a query to find students whose grade are more than or equal to 80.
Write a method public static ArrayList merge(ArrayList a, ArrayList b) that merges two array lists, alternating elements from both array lists. If one array list is shorter than the other, then alternate as long as you can and then append the remaining elements from the longer array list. For example, if a is 1 4 9 16 and b is 9 7 4 9 11 then merge returns the array list 1 9 4 7 9 4 16 9 11...
whats the answers How many total integers elements are in an array with 4 rows and 7 columns? 07 28 11 What is the resulting array contents, assuming that itemList is an array of size 4 having contents -55, -1, 0, 9? for (i = 0; i < 4; ++i) { itemsList[i] - i; -54,0, 1, 10 O 0, 1, 2, 3 O 1, 2, 3, 4 O-55,-1, 0,9 Given an integer array myVals of size N_SIZE (i.e. int[] myVals...